Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: yuewah on September 26, 2012, 12:51:14 AM

Title: [feature request] UICenterOnChild Event Callback
Post by: yuewah on September 26, 2012, 12:51:14 AM
Is it possible to add an event callback after the panel is centered ?
Title: Re: [feature request] UICenterOnChild Event Callback
Post by: ArenMook 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.
Title: Re: [feature request] UICenterOnChild Event Callback
Post by: yuewah on October 03, 2012, 09:14:45 PM
I have updated to v2.2.2, where is the example code ?
Title: Re: [feature request] UICenterOnChild Event Callback
Post by: ArenMook 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.
Title: Re: [feature request] UICenterOnChild Event Callback
Post by: yuewah on October 04, 2012, 10:57:37 AM
(http://mcdn3.angrybirdsnest.com/wp-content/uploads/2011/06/Angry-Birds-Seasons-Summer-Pignic-Episode-Selection-Screen.jpg)

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.
Title: Re: [feature request] UICenterOnChild Event Callback
Post by: ArenMook on October 04, 2012, 11:05:06 AM
The image link is broken to me.
Title: Re: [feature request] UICenterOnChild Event Callback
Post by: yuewah on October 04, 2012, 11:25:38 AM
updated with another image url.
Title: Re: [feature request] UICenterOnChild Event Callback
Post by: yuewah on October 15, 2012, 08:30:56 AM
@ArenMook, can you view the screenshot for the UI ?
Title: Re: [feature request] UICenterOnChild Event Callback
Post by: ArenMook on October 15, 2012, 12:11:14 PM
Yup I see it.
Title: Re: [feature request] UICenterOnChild Event Callback
Post by: yuewah 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. }
Title: Re: [feature request] UICenterOnChild Event Callback
Post by: loverains 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?
Title: Re: [feature request] UICenterOnChild Event Callback
Post by: yuewah on October 16, 2012, 04:12:51 AM
+= means adding multiple listeners, in this case, it is unnecessary.
Title: Re: [feature request] UICenterOnChild Event Callback
Post by: ArenMook on October 16, 2012, 07:59:49 AM
Sure, I'll add it.
Title: Re: [feature request] UICenterOnChild Event Callback
Post by: seandanger 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.