Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: getluky on November 30, 2012, 02:08:20 PM

Title: ActiveAnimation Update() with animations of different length
Post by: getluky on November 30, 2012, 02:08:20 PM
I'm running into an issue where using UIButtonAnimation's callWhenFinished gets called only after a delay from when my desired actual animation clip is finished. I believe I tracked it down to the fact that ActiveAnimation.Update() doesn't check if a specific clip is playing and instead uses the longest AnimationState in the loop to calculate an actual finished time. Because I have two animations, one of length 0.2f, another of length 1.0f, I think it's waiting until 1.0f is finished before calling callWhenFinished.

This seems incorrect to me - unless it is a specific requirement that all button animations attached must be of the same length. Am I misunderstanding something here? Adding a check for
  1. if (mAnim.IsPlaying (state.name)) {

under line 72 in ActiveAnimation.cs seems to make the finished event call instantly as expected.
Title: Re: ActiveAnimation Update() with animations of different length
Post by: ArenMook on December 01, 2012, 11:26:12 AM
ActiveAnimation doesn't play animations, per say. It advances them manually, sampling them itself. Reason for this is so that animations play while time scale is 0 (game is paused). If it wasn't the case, animations wouldn't work while the game is paused -- which is a bad thing for the UI.
Title: Re: ActiveAnimation Update() with animations of different length
Post by: getluky on December 01, 2012, 11:46:16 AM
@ArenMook: I understand, sorry for being confusing. To be more precise:

ActiveAnimation advances and samples ALL AnimationStates attached to mAnim, regardless of whether they have been set to playing by the Play method. This means that it won't trigger the finished callback until the longest animationstate has been completed (even though it is not included in the sampling because it is not set to playing). I think that's why a check to see if each AnimationState in the foreach loop is playing seems to make the finished callback call at the correct time even if there is a longer AnimationClip attached.

If I'm still not being clear, I can provide a sample project, just let me know. Thanks!
Title: Re: ActiveAnimation Update() with animations of different length
Post by: ArenMook on December 01, 2012, 04:39:46 PM
Hmm... I don't think I've ever had a use case with more than one animation on an object. I can take a look at this some more when I get home.
Title: Re: ActiveAnimation Update() with animations of different length
Post by: getluky on December 04, 2012, 09:56:46 AM
Hi @ArenMook, any chance to take a look at this issue?
Title: Re: ActiveAnimation Update() with animations of different length
Post by: ArenMook on December 04, 2012, 10:02:45 AM
Didn't get a chance. Got home, then had to pack / finish a bunch of things, and then fly out to Copenhagen.
Title: Re: ActiveAnimation Update() with animations of different length
Post by: HVS Brian on January 16, 2013, 03:59:34 PM
I'd like to bump this topic as well.  Is there a good reason not to support this modification?  When the timeScale is set to zero, there's really no other alternative (that I know of) for reliably triggering "callWhenFinished" functions at the intended time.

Edit: As a workaround, it would be possible to query the length of the desired animation state and run an internal timer in your Update() to call the desired function (or send a message) to achieve the same results.  Not as ideal as applying the suggested solution, but wanted to throw that out there.
Title: Re: ActiveAnimation Update() with animations of different length
Post by: ArenMook on January 16, 2013, 08:05:56 PM
Bumping the topic is usually a good idea for such things. ;)

I've added the modification locally and will see how it behaves.