In the process of updating an old project to a newer spine runtime (3.6). It seems like changes to the animation state event system no longer provide an easy path to stop listening for events.
previously we could do something like this -
// start listening to the event...
currentAnim.state.Complete += AnimComplete;
private void AnimComplete(Spine.AnimationState state, int trackIndex, int loopCount)
{
// stop listening to the event.
state.Complete -= AnimComplete;
}
but the way the API works now, the event you get back has a TrackEntry as a parameter - there's no clean way to get at the state that I can see -
// start listening to the event...
currentAnim.state.Complete += AnimComplete;
private void AnimComplete(Spine.TrackEntry trackEntry)
{
// how can i clean up the listener??
}
The documentation about this doesn't include a way to stop listening for events (http://esotericsoftware.com/spine-unity-events)
Is this an oversight? Or am I missing some backdoor way to get at the animation state from a TrackEntry? I'm dealing with a lot of legacy code here, so caching the Animation state could work, but it might get messy...
edit - I'll try answering my own question. I think the preferred way to do get a handle on the track entry & listen to that for completion instead of the AnimationState.
// cue up an animation & listen to the trackEntry for completion
TrackEntry trackEntry = currentAnim.AnimationState.SetAnimation(0, "jump", false);
trackEntry.Complete += AnimComplete;
private void AnimComplete(Spine.TrackEntry trackEntry)
{
trackEntry.Complete -= AnimComplete;
}
got around to testing my 'answer' and it seems like it doesn't work. I never see the callback fire when listening to the TrackEntry. BUT if I tap into the Complete event for the AnimationState, I see that Complete callback fire, so something weird is going on here. Best guess is some squirrely code is swapping out the TrackEntry out from under me and is no longer active? idk, gotta spend more time debugging it.