OverviewUIPlayAnimation script lets you trigger a remote animation using the event condition of your choice. It's nearly identical to the
UIPlayTween 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.
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:
public void MyNotification ()
{
Debug.Log(ActiveAnimation.current.name + " has finished playing!");
}
Pro-Tip- To easily play an animation via code, use the ActiveAnimation.Play() function like so:
ActiveAnimation.Play(targetAnimation, AnimationOrTween.Direction.Forward);
Class Documentationhttp://tasharen.com/ngui/docs/class_u_i_play_animation.htmlhttp://tasharen.com/ngui/docs/class_active_animation.htmlIf you have a question regarding this component or would like me to clarify something, just post a reply here.