Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: dlewis on November 07, 2012, 11:11:40 PM

Title: Tween delay via code
Post by: dlewis on November 07, 2012, 11:11:40 PM
I just had to modify NGUI so I could delay tweens when using TweenAlpha.Begin and thought I would share it so someone else could use it or could be added for future versions. The reason I didn't delay my calls to TweenAlpha is because the system is already in place for UITweener to delay so I wanted to leverage that.

UITweener.cs. Add the following code
  1. // Set the delay
  2. public void SetDelay(float delay)
  3. {
  4.         this.delay = delay;
  5. }
  6.  
  7. public void UpdateStartTime()
  8. {
  9.         mStartTime = Time.realtimeSinceStartup + delay;
  10. }

UITweener.cs. Replace Start() with the following
  1. void Start() { UpdateStartTime(); Update(); }

TweenAlpha.cs. Add a delay parameter to the Begin function

  1. static public TweenAlpha Begin (GameObject go, float duration, float delay, float alpha)

TweenAlpha.cs. Add the following lines before return comp. Same thing can be applied to any Tween.
  1. comp.SetDelay(delay);
  2. comp.UpdateStartTime();

Enjoy!
Title: Re: Tween delay via code
Post by: ArenMook on November 08, 2012, 04:39:46 AM
What is the point of the SetDelay() function when you can just use the "delay" property? o_O

There is also no reason for UpdateStartTime() function as both OnEnable and Start already add the delay:
  1.         /// <summary>
  2.         /// Record the starting time.
  3.         /// </summary>
  4.  
  5.         protected override void OnEnable () { base.OnEnable(); mStartTime = Time.realtimeSinceStartup + delay; }
  6.  
  7.         /// <summary>
  8.         /// Update on start, so there is no frame in-between.
  9.         /// </summary>
  10.  
  11.         void Start () { mStartTime = Time.realtimeSinceStartup + delay; Update(); }