OK - well I thought I understood how to set it up, but I'm still missing something. I have a helper method that sets up the queue with animations with random delays between them. I then have a listener on the last track entry to find out when all of the animations have finished playing and then I restart them after clearing out the tracks:
public static void PlayAnimationQueue (string[] animationNames, float randomDelayMax, SkeletonAnimation skeletonAnimation, bool loop = false, bool separateTracks = false) {
int track = 0;
TrackEntry lastTrackEntry = null;
foreach (string animationName in animationNames) {
lastTrackEntry = skeletonAnimation.state.AddAnimation (separateTracks ? track++ : 0, animationName, false, Random.Range (0, randomDelayMax));
lastTrackEntry.Complete += (Spine.AnimationState state, int trackIndex, int loopCount) => {
Debug.Log ("State = " + state + " Track = " + track);
};
}
if (loop && lastTrackEntry != null) {
lastTrackEntry.Complete += (Spine.AnimationState state, int trackIndex, int loopCount) => {
skeletonAnimation.state.ClearTracks ();
PlayAnimationQueue (animationNames, randomDelayMax, skeletonAnimation, loop, separateTracks);
};
}
}
This is used like this (I set an initial animation first):
characterFaceAnimation.state.SetAnimation (0, "blinking", false);
SpineCharacters.PlayAnimationQueue (new string[] {
"eye move right",
"idle3",
"idle2",
"smile",
"blinking"
}, 5f, characterFaceAnimation, true);
This seems to work the first time, but then the second time through after clearing tracks and adding animations again, the animations seem to be out of order and playing on top of each other.
Is there something more I need to do than clear tracks to remove the previous animations? Or is there some way of looping back to the start of the first list of animations instead of recreating the list each time?