Author Topic: UiCenterOnChild -- Did something change?  (Read 1889 times)

wallabie

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 200
    • View Profile
UiCenterOnChild -- Did something change?
« on: June 21, 2014, 01:23:11 AM »
I have a SV with a grid that has a CenterOnChild comp.

It has been working fine before but with the recent updates it's not centering anymore.  I checked my setup and it's fine but still not working.  Has something changed besides the detection of disabled items?  I don't have the code for UIcenterOnChild from the previous version so I cannot do a diff.

wallabie

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 200
    • View Profile
Re: UiCenterOnChild -- Did something change?
« Reply #1 on: June 21, 2014, 04:40:30 AM »
A couple more issues:

1. In the inspector, the CenterOnChild comp is enabled and the items in the SV are populated dynamically.  After populating, the the CenterOnChild doesn't work, I have to manually deactivate and activate it then it starts working.

2. When the user drags the SV to a new child, I would like to be able to get an event ASAP when the CenterOn() is finished.  ATM,  the available methods of getting the new child is not working fast enough.  I'm using onFinished event which is quite bit of time after the CenterOn finishes.   I added :

   public delegate void OnCenteredObjectCallBack (GameObject centeredObject);
   public static event OnCenteredObjectCallBack OnCenteredObject;

and to the bottom of the CenterOn() method:

      else mCenteredObject = null;
                if(OnCenteredObject != null)
          OnCenteredObject(mCenteredObject);

This gives the desired result.  Can you add this functionality in a future version so that I don't have to add the changes to NGUI with each new version. 

Cheers.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UiCenterOnChild -- Did something change?
« Reply #2 on: June 21, 2014, 03:52:16 PM »
The last two changes I see to the script were line 103 where I added a check to skip inactive objects, and line 184 where I added the "#if UNITY_EDITOR" section, making it possible to execute the script via right-click in the inspector.

From there on, the changes include doing nothing in the Recenter() function if the transform.childCount is zero... and that's it, no other changes since February.

1. The script doesn't cache the list of children anywhere, but it does perform its logic in its OnEnable() function -- so maybe your order of execution simply changed (are you doing your child creation in some other OnEnable function?). You will want to call UICenterOnChild's Recenter() function after populating your content.

2. Sure. I'll add it -- however I'm going to make it a delegate member, not a static event.

wallabie

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 200
    • View Profile
Re: UiCenterOnChild -- Did something change?
« Reply #3 on: June 22, 2014, 01:02:44 AM »
Cheers.