I'm setting up an anim system that has a standard idle animation and I want to be able to throw in single non loop anims and have it return to idle once thats done, but I'm having touble w the logic and/or code behind end / complete & accessing loop info.
Checking for trackEntry.IsComplete inside the End callback works, but seems unideal
what if i want to stop the animation and return to idle before a full loop is complete?
I think if I could just properly pull the loop info out it would solve my problem, but as you can see in the comments of my code below, all the loop info pulling i've tried always returns true, even when I've done something like SetAnimation(0, "smug", false) (which, correctly, doesnt loop, so im not sure why this is happening).
Thanks in advance!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Spine;
using Spine.Unity;
public class Scr_SpineCtrl : MonoBehaviour {
public SkeletonAnimation spineAnim;
void Start () {
spineAnim = this.GetComponent<SkeletonAnimation> ();
//listen for special events defined in spine eg footsteps
spineAnim.state.Event += HandleEvent;
//listen for starts
spineAnim.state.Start += delegate (TrackEntry trackEntry) {
Debug.Log ("a new animation started");
};
//listen for ends
spineAnim.state.End += delegate (TrackEntry trackEntry){
Debug.Log ("an animation ended");
HandleEnd(trackEntry);
};
//listen for completes
spineAnim.state.Complete += delegate {
Debug.Log ("a loop was completed");
};
}
public void PlayAnim (string name, bool loop){
spineAnim.AnimationState.SetAnimation (0, name, loop);
}
void HandleEnd (TrackEntry trackEntry){
//THIS WORKS BUT IS NOT IDEAL?
//if looped AND ended (ie full cycle of a non looping anim)
if (trackEntry.IsComplete) {
PlayAnim ("idle", true);
}
//failed attempt
// .loop returns true presumably bc set and stayed at true in inspector...
if (spineAnim.loop != true) {
Debug.Log ("tiiiime to play idle!");
PlayAnim ("idle", true);
}
//other failed attempt
// .Loop returns true even though the anim was set to not loop...
if (trackEntry.Loop != true) {
Debug.Log ("time to play idle");
PlayAnim ("idle", true);
}
}
}