Author Topic: Possible bug: UIButtonTween.disableWhenFinished not working correctly  (Read 2913 times)

abacus

  • Guest
I think I found a bug in NGUI (paid) version 2.3.3f.

I have two gameobjects called Panel1 and Panel2, with the following attached:
 * Panel1
    * UIPanel
    * TweenPosition: TweenGroup=0 (forward = moves panel off screen to the left).
    * Button (name="next")
       * UIButtonTween: Target=Panel1, TweenGroup=0, direction=forward, disableWhenFinished=DisableAfterForward
       * UIButtonTween: Target=Panel2, TweenGroup=0, direction=forward, disableWhenFinished=DoNotDisable
* Panel2
   * UIPanel
   * TweenPosition: TweenGroup=0 (forward = moves panel onto screen from the right).
   * TweenPosition: TweenGroup=1 (forward = moves panel off screen to the left).
   * Button (name="back")
       * UIButtonTween: Target=Panel1, TweenGroup=0, direction=reverse, disableWhenFinished=DoNotDisable
       * UIButtonTween: Target=Panel2, TweenGroup=0, direction=reverse, disableWhenFinished=DisableAfterReverse
   * Button (name="done")
       * UIButtonTween: Target=Panel2, TweenGroup=1, direction=forward, disableWhenFinished=DisableAfterForward

The problem here is when I click the "back"-button. According to my setup, Panel2 should be disabled after the tweening is done (TweenGroup 0 on Panel2).
But this does not happen. I looked at the code, and I think it is because UIButtonTweener.Update() checks ALL the UITweener-objects of the target (which in
this case is Panel2), and sets properDirection=false since the UITweener of TweenGroup=1 is forward.

I fixed it by adding a check for tween group in UIButtonTween.Update(), i.e. changing it from

  1. void Update ()
  2. {
  3.     if (disableWhenFinished != DisableCondition.DoNotDisable && mTweens != null)
  4.     {
  5.         bool isFinished = true;
  6.         bool properDirection = true;
  7.  
  8.         for (int i = 0, imax = mTweens.Length; i < imax; ++i)
  9.         {
  10.             UITweener tw = mTweens[i];
  11.  
  12.             if (tw.enabled)
  13.             {
  14.                 isFinished = false;
  15.                 break;
  16.             }
  17.             else if ((int)tw.direction != (int)disableWhenFinished)
  18.             {
  19.                 properDirection = false;
  20.             }
  21.         }
  22.  
  23.         if (isFinished)
  24.         {
  25.             if (properDirection) NGUITools.SetActive(tweenTarget, false);
  26.             mTweens = null;
  27.         }
  28.     }
  29. }
  30.  

to

  1. void Update ()
  2. {
  3.     if (disableWhenFinished != DisableCondition.DoNotDisable && mTweens != null)
  4.     {
  5.         bool isFinished = true;
  6.         bool properDirection = true;
  7.  
  8.         for (int i = 0, imax = mTweens.Length; i < imax; ++i)
  9.         {
  10.             UITweener tw = mTweens[i];
  11.  
  12.             if (tw.tweenGroup == tweenGroup) // CHECK FOR TWEENGROUP!
  13.             {
  14.                 if (tw.enabled)
  15.                 {
  16.                     isFinished = false;
  17.                     break;
  18.                 }
  19.                 else if ((int)tw.direction != (int)disableWhenFinished)
  20.                 {
  21.                     properDirection = false;
  22.                 }
  23.             }
  24.         }
  25.  
  26.         if (isFinished)
  27.         {
  28.             if (properDirection) NGUITools.SetActive(tweenTarget, false);
  29.             mTweens = null;
  30.         }
  31.     }
  32. }
  33.  
   
Am I right, or am I using the NGUI system incorrectly?


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Possible bug: UIButtonTween.disableWhenFinished not working correctly
« Reply #1 on: March 05, 2013, 12:56:12 PM »
Sounds like you found a valid bug -- you are likely the first person to use tween groups like this. Thanks for the fix!