Author Topic: UIPlayAnimation  (Read 20887 times)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
UIPlayAnimation
« on: November 23, 2013, 06:46:29 AM »
Overview

UIPlayAnimation 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:
  1. public void MyNotification ()
  2. {
  3.     Debug.Log(ActiveAnimation.current.name + " has finished playing!");
  4. }

Pro-Tip
  • To easily play an animation via code, use the ActiveAnimation.Play() function like so:
  1. ActiveAnimation.Play(targetAnimation, AnimationOrTween.Direction.Forward);

    Class Documentation

    http://tasharen.com/ngui/docs/class_u_i_play_animation.html
    http://tasharen.com/ngui/docs/class_active_animation.html

    If you have a question regarding this component or would like me to clarify something, just post a reply here.

    jeldrez

    • Sr. Member
    • ****
    • Thank You
    • -Given: 8
    • -Receive: 4
    • Posts: 352
      • View Profile
    Re: UIPlayAnimation
    « Reply #1 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.

    BongoMongo

    • Newbie
    • *
    • Thank You
    • -Given: 0
    • -Receive: 0
    • Posts: 2
      • View Profile
    Re: UIPlayAnimation
    « Reply #2 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();
    or
    1.  m_OpenAnimation.target.Rewind(m_OpenAnimation.clipName);
    or
    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?

    Cheers

    ArenMook

    • Administrator
    • Hero Member
    • *****
    • Thank You
    • -Given: 337
    • -Receive: 1171
    • Posts: 22,128
    • Toronto, Canada
      • View Profile
    Re: UIPlayAnimation
    « Reply #3 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.

    BongoMongo

    • Newbie
    • *
    • Thank You
    • -Given: 0
    • -Receive: 0
    • Posts: 2
      • View Profile
    Re: UIPlayAnimation
    « Reply #4 on: June 23, 2014, 07:02:47 AM »
    Thank you, that solved my problem!  ;)

    Raptcha911

    • Newbie
    • *
    • Thank You
    • -Given: 0
    • -Receive: 0
    • Posts: 2
      • View Profile
    Re: UIPlayAnimation
    « Reply #5 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..

    ArenMook

    • Administrator
    • Hero Member
    • *****
    • Thank You
    • -Given: 337
    • -Receive: 1171
    • Posts: 22,128
    • Toronto, Canada
      • View Profile
    Re: UIPlayAnimation
    « Reply #6 on: September 24, 2014, 02:46:44 PM »
    Did you not even look at the class, or its documentation before asking that?

    http://www.tasharen.com/ngui/docs/class_active_animation.html#afdee2db0f7af94bf5c4d9958d658d001

    ActiveAnimation.isPlaying is there.