Author Topic: UIPlayTween Bug?  (Read 3174 times)

wishful_st

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
UIPlayTween Bug?
« on: January 22, 2014, 08:49:29 PM »
Hi there,

I've been using UIPlayTween and the OnFinished event to chain animations.  However, I've seem to come up with a problem for my use case, where OnFinished doesn't seem to be called or gets called at later time when UIPlay triggers an animation that's already finished.  I haven't figured out exactly what is going on, but have managed to how to fix it somewhat via a minor modification in UIPlayTween.cs OR UITweener.cs after a little bit of debugging.

I'm using NGUI 3.0.9f4.  In UIPlayTween.cs:305, moved the EventDelegate.Add() before the preceding if block (to line 292).  Since I suspected the culprit to be stuff happening inside tw.Play() on line 301, another way that I fixed my issue was to, in UITweener.cs, remove the Update() on line 345 inside the Play function.  I'm not sure if by doing either of these breaks anything else, but just wanted to pose the question out there.  I have a sense that it may have something to do with the event not kicking in because of the edge case that the animation was already done (tweenFactor already == 1), hence the event stuff doesn't kick in (some stuff that's supposed to happen in Update, didn't).  I'm not exactly sure, and I've found a working solution for now, so I'll leave it to the expert to correct me or the issue.

I've attached a sample scene that demos the issue (without the NGUI source, of course).

Please let me know if this is legit or if I'm doing something incorrectly.  Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIPlayTween Bug?
« Reply #1 on: January 23, 2014, 06:10:20 AM »
Good find, thanks. You can actually fix it by modifying UIPlayTween's Play function around the lines you mentioned:
  1.                                 // If the tweener's group matches, we can work with it
  2.                                 if (tw.tweenGroup == tweenGroup)
  3.                                 {
  4.                                         // Ensure that the game objects are enabled
  5.                                         if (!activated && !NGUITools.GetActive(go))
  6.                                         {
  7.                                                 activated = true;
  8.                                                 NGUITools.SetActive(go, true);
  9.                                         }
  10.  
  11.                                         ++mActive;
  12.  
  13.                                         // Toggle or activate the tween component
  14.                                         if (playDirection == Direction.Toggle)
  15.                                         {
  16.                                                 // Listen for tween finished messages
  17.                                                 EventDelegate.Add(tw.onFinished, OnFinished, true);
  18.                                                 tw.Toggle();
  19.                                         }
  20.                                         else
  21.                                         {
  22.                                                 if (resetOnPlay || (resetIfDisabled && !tw.enabled)) tw.ResetToBeginning();
  23.                                                 // Listen for tween finished messages
  24.                                                 EventDelegate.Add(tw.onFinished, OnFinished, true);
  25.                                                 tw.Play(forward);
  26.                                         }
  27.                                 }