I'm not sure what you're describing.
Are you saying you want, if "walk" transitions to "jump", call this method?
If your code is calling SetAnimation, wouldn't you be able to be aware of this already?
If not at the point of SetAnimation, it would also make sense for this check to be in Start
or End
callbacks, depending on what timing you want.
For example:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
namespace Spine.Unity.Examples {
public class TransitionCallbackExample : MonoBehaviour {
public SkeletonAnimation skeletonAnimation;
[SpineAnimation(dataField: "skeletonAnimation")]
public string from, to;
public UnityEvent TransitionStarted;
public UnityEvent TransitionEnded;
Spine.Animation fromAnimation, toAnimation;
void Awake () {
if (skeletonAnimation == null)
this.enabled = false;
}
void Start () {
skeletonAnimation.Initialize(false);
if (!skeletonAnimation.valid) return;
if (string.IsNullOrEmpty(from) || string.IsNullOrEmpty(to)) return;
var skeletonData = skeletonAnimation.Skeleton.Data;
fromAnimation = skeletonData.FindAnimation(from);
toAnimation = skeletonData.FindAnimation(to);
skeletonAnimation.AnimationState.Start += HandleStart;
}
void HandleStart (TrackEntry trackEntry) {
var mixingFrom = trackEntry.mixingFrom;
if (mixingFrom == null) return; // no previous animation.
bool transitionMatch = trackEntry.Animation == toAnimation && mixingFrom.Animation == fromAnimation;
if (transitionMatch) {
if (TransitionStarted != null) TransitionStarted.Invoke();
mixingFrom.End += HandleTransitionEnd; // Wait for the track to end.
}
}
private void HandleTransitionEnd (TrackEntry trackEntry) {
//trackEntry.End -= HandleTransitionEnd; // TrackEntries are in a pool but AnimationState handles this cleanup.
if (TransitionEnded != null) TransitionEnded.Invoke();
}
}
}