NGUI UICenterOnChild, find out what is centered

Hi guys,

I’m having trouble figuring out how to find out programatically on which item does my NGUI grid center. I have a menu where items can be dragged horizontally and they get centered using UICenterOnChild. What I want is to find out from the script which item the menu is currently centered on.

I looked at the documentation of UICenterOnChild and there is a “delegate void UICenterOnChild.OnCenterCallback(GameObject centeredObject)”. There’s also a function “UICenterOnChild.onCenter” which triggers when a new object is being centered.

Probably the reason I don’t quite understand the documentation is because I don’t know how to use delegates yet. I thought I knew what they were and after looking at the unity’s tutorial on delegates didn’t find anything new but apparently I don’t understand them enough to figure out how to achieve what I want in this case.

If anyone has any idea how to get that info I’ll be happy to hear it.

Thanks in advance for you time.

I resolved the issue myself. For others having the same question, here’s how to do this:

Create an UICenterOnChild variable (let’s say its name is myCenteringGrid),
Plug in your desired UICenterOnChild in there,
Then make myCenteringGrid.onCenter equal to your desired function which you want to fire when the UICenterOnChild starts centering on a new object in the grid. onCenter is an instance of a OnCenterCallback delegate.
Your desired function must have the same return value and input parameters as the original delegate (that is OnCenterCallback). In this case the return type is VOID and the parameter is a GameObject (which is a gameobject being centered).