Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: ngui on January 22, 2014, 02:44:29 PM
-
I'd like to assign a method to UICenterOnChild.onFinished, so that a UIScrollView can detect when a change has occurred.
Is there another method that's more appropriate?
-
any solution?
-
UICenterOnChild.onFinished is triggered when the movement operation completes and the scroll view gets centered on a new object. It doesn't detect whether it's the same object you started on or not. If you want that kind of logic, just do a simple "if (last != new)" type check in your code.
-
Well I just want a method to be called whenever some movement happens. How would I set the UICenterOnChild.onFinished then?
-
Don't. Just create a script with an Update() function in it. Record the position, check if the position changed in the Update(). There you go.
-
is there any particular reason why you would not recommend it? I didn't want run an additional check in Update (instead piggyback on what checks UICenterOnChild is already running) or do something in Update that may be overwritten in a child class.
And just for my own knowledge I'd like to get an idea of how to cast to the delegate 'SpringPanel.OnFinished'. Thank you.
-
The delegate was meant to execute when it finishes. You want it to execute while it's moving, which is quite different -- so Update() is the way to go in your case.
SpringPanel.OnFinished is just a "void FuncName()" delegate. So if you have "void MyFunc() {}", to add it you do spring.onFinished += MyFunc;
-
actually my intention was to call it when it finishes, so I think it'll work out perfectly. Thank you for being so incredibly helpful! :D
-
Additionally, how would I cast/assign an EventDelegate to the SpringPanel.onFinished delegate? and in general get the callback from the EventDelegate (for passing about)?
-
EventDelegate class that comes with NGUI is not the same as just "delegate". EventDelegate is an NGUI class while 'delegate' is a system type. EventDelegates can be set from inspector, while system delegates are meant to be used only via code.
The system delegates were kept for backwards compatibility / performance reasons, as it's always a tiny bit faster to just call a system delegate than a custom one.
-
Thanks I just wanted to know if you had any further details, I got it working.