Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: ngui on January 22, 2014, 02:44:29 PM

Title: Assign an EventDelegate to UICenterOnChild.onFinished
Post 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?
Title: Re: Assign an EventDelegate to UICenterOnChild.onFinished
Post by: ngui on January 24, 2014, 12:55:05 AM
any solution?
Title: Re: Assign an EventDelegate to UICenterOnChild.onFinished
Post by: ArenMook on January 24, 2014, 10:23:58 AM
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.
Title: Re: Assign an EventDelegate to UICenterOnChild.onFinished
Post by: ngui on January 24, 2014, 01:56:21 PM
Well I just want a method to be called whenever some movement happens. How would I set the UICenterOnChild.onFinished then?
Title: Re: Assign an EventDelegate to UICenterOnChild.onFinished
Post by: ArenMook on January 24, 2014, 11:57:13 PM
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.
Title: Re: Assign an EventDelegate to UICenterOnChild.onFinished
Post by: ngui on January 25, 2014, 11:31:44 AM
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.
Title: Re: Assign an EventDelegate to UICenterOnChild.onFinished
Post by: ArenMook on January 25, 2014, 03:48:54 PM
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;
Title: Re: Assign an EventDelegate to UICenterOnChild.onFinished
Post by: ngui on January 26, 2014, 02:17:40 PM

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
Title: Re: Assign an EventDelegate to UICenterOnChild.onFinished
Post by: ngui on January 26, 2014, 03:28:31 PM
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)?
Title: Re: Assign an EventDelegate to UICenterOnChild.onFinished
Post by: ArenMook on January 26, 2014, 09:15:36 PM
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.
Title: Re: Assign an EventDelegate to UICenterOnChild.onFinished
Post by: ngui on January 27, 2014, 01:56:25 AM
Thanks I just wanted to know if you had any further details, I got it working.