Author Topic: [feature request] UICenterOnChild Event Callback  (Read 16263 times)

yuewah

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 180
    • View Profile
[feature request] UICenterOnChild Event Callback
« on: September 26, 2012, 12:51:14 AM »
Is it possible to add an event callback after the panel is centered ?
« Last Edit: September 26, 2012, 03:38:43 AM by yuewah »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [feature request] UICenterOnChild Event Callback
« Reply #1 on: September 26, 2012, 10:07:18 AM »
I added that script as an example of how it can be done. Feel free to modify it or its copy to suit your needs. Adding an event should be trivial.

yuewah

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 180
    • View Profile
Re: [feature request] UICenterOnChild Event Callback
« Reply #2 on: October 03, 2012, 09:14:45 PM »
I have updated to v2.2.2, where is the example code ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [feature request] UICenterOnChild Event Callback
« Reply #3 on: October 04, 2012, 10:12:14 AM »
I think you misunderstood what I meant. What I was trying to say is that the UICenterOnClick script was an example in response to a question that was asked fairly frequently. Adding a callback to be triggered at the end is a trivial task, so I simply suggested you modify that script or create a copy of it with the added callback.

yuewah

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 180
    • View Profile
Re: [feature request] UICenterOnChild Event Callback
« Reply #4 on: October 04, 2012, 10:57:37 AM »


The UI with some dot indicator at the bottom used for level selection is quite common on mobile game. It make use of the callback event. I hope that NGUI will support it in the future.
« Last Edit: October 04, 2012, 11:24:47 AM by yuewah »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [feature request] UICenterOnChild Event Callback
« Reply #5 on: October 04, 2012, 11:05:06 AM »
The image link is broken to me.

yuewah

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 180
    • View Profile
Re: [feature request] UICenterOnChild Event Callback
« Reply #6 on: October 04, 2012, 11:25:38 AM »
updated with another image url.

yuewah

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 180
    • View Profile
Re: [feature request] UICenterOnChild Event Callback
« Reply #7 on: October 15, 2012, 08:30:56 AM »
@ArenMook, can you view the screenshot for the UI ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [feature request] UICenterOnChild Event Callback
« Reply #8 on: October 15, 2012, 12:11:14 PM »
Yup I see it.

yuewah

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 180
    • View Profile
Re: [feature request] UICenterOnChild Event Callback
« Reply #9 on: October 15, 2012, 10:04:58 PM »
I think this UI design is quite common, for the dot indicator shown at the bottom correctly, onCenterFinished callback is necessary, would you add the following code to them main branch ?

  1. public class UICenterOnChild : MonoBehaviour
  2. {
  3.  
  4.         public delegate void OnCenterFinished();
  5.         public OnCenterFinished onCenterFinished;
  6.  
  7.         public void Recenter()
  8.         {
  9.                 ...
  10.                 SpringPanel springPanel = SpringPanel.Begin(mDrag.gameObject, dt.localPosition - offset, 8f);
  11.                 springPanel.onSpringFinished = OnSpringFinished;
  12.                 ...
  13.         }
  14.  
  15.         void OnSpringFinished()
  16.         {
  17.                 if ( onCenterFinished != null )
  18.                         onCenterFinished();
  19.         }
  20. }

  1. public class SpringPanel : IgnoreTimeScale
  2. {
  3.         public delegate void OnSpringFinished();
  4.         public OnSpringFinished onSpringFinished;
  5.  
  6.         void Update ()
  7.         {
  8.                 ...
  9.                 if (mThreshold >= Vector3.Magnitude(after - target))
  10.                 {
  11.                         ...
  12.                         if (onSpringFinished != null) onSpringFinished();
  13.                 }
  14.         }
  15.  
  16. }

loverains

  • Guest
Re: [feature request] UICenterOnChild Event Callback
« Reply #10 on: October 15, 2012, 10:46:11 PM »
 public void Recenter()
    {
        if (mDrag == null)
        {
            mDrag = UITools.FindInParents<UIDraggablePanel>(gameObject);

            if (mDrag == null)
            {
                Debug.LogWarning(GetType() + " requires " + typeof(UIDraggablePanel) + " on a parent object in order to work", this);
                enabled = false;
                return;
            }
            else
            {
                mDrag.onDragFinished = OnDragFinished;
            }
        }

this delegate why not use += operator?

yuewah

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 180
    • View Profile
Re: [feature request] UICenterOnChild Event Callback
« Reply #11 on: October 16, 2012, 04:12:51 AM »
+= means adding multiple listeners, in this case, it is unnecessary.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [feature request] UICenterOnChild Event Callback
« Reply #12 on: October 16, 2012, 07:59:49 AM »
Sure, I'll add it.

seandanger

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 32
    • View Profile
    • Bit By Bit Studios
Re: [feature request] UICenterOnChild Event Callback
« Reply #13 on: November 29, 2012, 09:02:49 PM »
+= means adding multiple listeners, in this case, it is unnecessary.

To be clear, += means to append a listener to the delegate list, instead of replacing them.  Using = overwrites any other listeners that may be attached to that delegate.

For that reason, I think this should be +=, I don't want my UIDraggablePanel's other delegates being overwritten by this component.