Author Topic: Assign an EventDelegate to UICenterOnChild.onFinished  (Read 7664 times)

ngui

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Assign an EventDelegate to UICenterOnChild.onFinished
« 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?

ngui

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: Assign an EventDelegate to UICenterOnChild.onFinished
« Reply #1 on: January 24, 2014, 12:55:05 AM »
any solution?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Assign an EventDelegate to UICenterOnChild.onFinished
« Reply #2 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.

ngui

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: Assign an EventDelegate to UICenterOnChild.onFinished
« Reply #3 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?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Assign an EventDelegate to UICenterOnChild.onFinished
« Reply #4 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.

ngui

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: Assign an EventDelegate to UICenterOnChild.onFinished
« Reply #5 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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Assign an EventDelegate to UICenterOnChild.onFinished
« Reply #6 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;

ngui

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: Assign an EventDelegate to UICenterOnChild.onFinished
« Reply #7 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

ngui

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: Assign an EventDelegate to UICenterOnChild.onFinished
« Reply #8 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)?
« Last Edit: January 26, 2014, 03:42:04 PM by ngui »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Assign an EventDelegate to UICenterOnChild.onFinished
« Reply #9 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.

ngui

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: Assign an EventDelegate to UICenterOnChild.onFinished
« Reply #10 on: January 27, 2014, 01:56:25 AM »
Thanks I just wanted to know if you had any further details, I got it working.