eko_lx

Hi,

I use SkeletonGraphic UI to animate.

mySkeletonGraphic.AnimationState.SetAnimation(0, animeRef, loop).TimeScale = timeScale;

After completion I would like to reset animation to default state (which is set in Inspector) or if there an option to set default (idle) state and on each completion to return to that state.

I know there are events as OnComplete but to subscribe to each animation state and then unsubscribe - it's frustrating I think.

But anyway OnComplete event doesn't work for me since it will run on each completion even if animation is set to loop.

I need run move_animation on button click and as soon as first animation complete loop the idle_animation.
eko_lx
  • Сообщения: 4

Harald

eko_lx писал(а):I know there are events as OnComplete but to subscribe to each animation state and then unsubscribe - it's frustrating I think.
You have two ways of subscribing to AnimationStateListener callbacks:
  1. registering at the AnimationState for any animation via skeletonAnimation.AnimationState.Complete += YourMethod.
  2. for the events of a single TrackEntry via
    var trackEntry = animationState.SetAnimation(0, "walk", true);
    trackEntry.Complete += YourMethod;
You don't need to subscribe and unsubscribe every time.
Note that it's Complete and not OnComplete, which is an internal method.
eko_lx писал(а):But anyway OnComplete event doesn't work for me since it will run on each completion even if animation is set to loop.
I need run move_animation on button click and as soon as first animation complete loop the idle_animation.
This sounds more as if you want to use the End event then. Please have a look at the documentation here for which event suits your needs: AnimationStateListener
Аватара пользователя
Harald

Harri
  • Сообщения: 2778

eko_lx

On end of one animation I need to run another one.

Using even End event I will enter into the loop of events.
So, there are only one solution is to unsubscribe from event if the current animation state is a loop.
eko_lx
  • Сообщения: 4

Harald

I'm afraid I don't understand what you are trying to achieve. Could you please describe the whole use case: what animations are playing, what you would like to happen, why you set some animations to looping, eventually what should be able to interrupt animations, etc.
Аватара пользователя
Harald

Harri
  • Сообщения: 2778

eko_lx

I need to run one animation (let's say "move_animation") on button click and as soon as first animation complete run the second animation ("idle_animation") and set loop to true.

Whenever I will click the button repeat the same routine.

If I will subscribe to End event or any other event this routine will run infinitely from first button click.
eko_lx
  • Сообщения: 4

Harald

The easiest way would be to call SetAnimation() to immediately start "move_animation", immediately followed by calling AddAnimation() for "idle_animation".

If you really want to use the callback delegate methods, you just have to register to End or Complete of the first animation, as I said earlier.
var trackEntry = animationState.SetAnimation(0, "move_animation", false);
trackEntry.Complete += SwitchToIdleMethod;
I fail to see what would cause problems with the above code.
eko_lx писал(а):If I will subscribe to End event or any other event this routine will run infinitely from first button click.
No, it will not if you register to trackEntry.Complete or trackEntry.End.
Аватара пользователя
Harald

Harri
  • Сообщения: 2778

eko_lx

Thank you
eko_lx
  • Сообщения: 4

Harald

You're welcome.
Аватара пользователя
Harald

Harri
  • Сообщения: 2778


Вернуться в Unity