Tasharen Entertainment Forum

Support => NGUI 3 Documentation => Topic started by: ArenMook on November 23, 2013, 06:46:29 AM

Title: UIPlayAnimation
Post by: ArenMook on November 23, 2013, 06:46:29 AM

UIPlayAnimation script lets you trigger a remote animation using the event condition of your choice. It's nearly identical to the UIPlayTween (http://www.tasharen.com/forum/index.php?topic=6760) script, except that it works with animations instead.


To add an animation to a widget, your best bet is to record it by hitting CTRL+6 within Unity to open up the Animation window (http://docs.unity3d.com/Documentation/Components/animeditor-UsingAnimationEditor.html).

If you're aiming to try it out, you can also just drag & drop the Checkmark animation that comes with NGUI. Either way, you will most likely want to uncheck its Play Automatically field, as leaving it on will make the animation play as soon as you hit the Play button to test your game.

To trigger the remote animation, attach the UIPlayAnimation component (Attach -> Play Animation). You will be presented with a variety of customizable options.

First comes the Clip Name that lets you choose which clip from the animation will actually be played. You can leave it empty if your animation doesn't contain multiple clips.

The Trigger Condition lets you choose which action is going to trigger the animation to play, and Play Direction controls which way it will play. You can choose what happens with the selected object, if you wish. It's something to think about when creating a controller-based game, since something must always be selected, and if you happen to use animations to hide one window and open another then you will likely want to transfer the selection status to some other button.

If the target is disabled, you can choose to activate it or let it remain disabled. If you had an animation to fade in one window and fade out another, you could specify the window to be disabled when the fading-out is done by choosing the Disable option under When finished, and specify Enable then play for the other. This approach would ensure that the windows would be disabled after the animation finishes, but would be enabled again when they should be fading in.

If the animation is already playing you can choose to restart it from the beginning if you wish.

Finally, if you want to execute some remote function once the animation finishes playing, you can do so by dragging the targeted game object into the Notify field and choosing the appropriate function from the list. Like all NGUI notifications it must be of "public void FuncName (void)" type, like this:
  1. public void MyNotification ()
  2. {
  3.     Debug.Log(ActiveAnimation.current.name + " has finished playing!");
  4. }

  1. ActiveAnimation.Play(targetAnimation, AnimationOrTween.Direction.Forward);

Class Documentation


If you have a question regarding this component or would like me to clarify something, just post a reply here.
Title: Re: UIPlayAnimation
Post by: jeldrez on November 25, 2013, 12:21:50 PM
I used to use ActiveAnimation.Play, but when you want to play several clips from the same Animation just play the first one. Doesn't exist a blend option like Unity one.

  1. animation.Play("walk");
  2. animation.Blend("run", weightRun, 0.1);

IMHO, blending is missing.
Title: Re: UIPlayAnimation
Post by: BongoMongo on June 18, 2014, 04:41:26 AM
I have a button that is supposed to open a menu if I press it once and closes the menu if I press again - a simple Popup. I want to animate the open and close transition with two separate animations. Everything works fine for the first time but if you try to open the menu again, the open animation does not play and is stuck at the end.

I've tried several approaches to reset the animation, for instance:
  1. m_OpenAnimation.target.Rewind();
  1.  m_OpenAnimation.target.Rewind(m_OpenAnimation.clipName);
  1. ActiveAnimation.current.Reset()
but none of these approaches seem to work.
The only thing that does work is to play the animation backwards via
  1. m_OpenAnimation.Play(false);

How can I reset the animation to the beginning?

Title: Re: UIPlayAnimation
Post by: ArenMook on June 18, 2014, 08:21:03 PM
Use ActiveAnimation.Play, not UIPlayAnimation. You have 2 custom animations, so write a quick script to play one or the other using ActiveAnimation.Play.
Title: Re: UIPlayAnimation
Post by: BongoMongo on June 23, 2014, 07:02:47 AM
Thank you, that solved my problem!  ;)
Title: Re: UIPlayAnimation
Post by: Raptcha911 on September 24, 2014, 06:04:20 AM
how to check if an activeanimation is playing??I mean is there anything like ActiveAnimation.isPlaying??? ...I'm having a problem of more than one animation happening at a time. Suppose, a player is in the menu screen and touches two buttons at once. UIPlayAnimation is taking both the touches together and playing two animations together, resulting in two overlapped panels in the screen. So, on button press I need to check if any animation is happening before I let that button trigger a new animation..
Title: Re: UIPlayAnimation
Post by: ArenMook on September 24, 2014, 02:46:44 PM
Did you not even look at the class, or its documentation before asking that?


ActiveAnimation.isPlaying is there.