What's getAnim
?
I recommend reading this: https://github.com/pharan/spine-unity-docs/blob/master/Animation.md#trackentry
I'll be adding a few things to elaborate, 'cause it looks like someone would get confused in the context of what you were trying to do.
In any case, here's a short description of what happens when you call SetAnimation:
- You call
mySkeletonAnimation.state.SetAnimation
.
- SkeletonAnimation's AnimationState generates a TrackEntry object (which stores current time of that animation playback instance) and adds it to its internal track system to be automatically managed, updated, and applied to the skeleton.
- SetAnimation returns the TrackEntry object so you can do whatever you want with it.
so you can say:
Spine.TrackEntry myTrackEntry = mySkeletonAnimation.state.SetAnimation(0, "run", true);
myTrackEntry.time = 0.5f; // jumps to the 0.5 seconds mark.
//myTrackEntry.lastTime = 0.5f; // Optional. Originally 0. prevents events within the 0-0.5 range from firing immediately. But also ignores Attachment keys right now. This will change in 3.0.
The code above will cause the animation to start playing at 0.5 seconds.
Then SkeletonAnimation's AnimationState object will continue to update and manage the TrackEntry
itself.
Internally, it calls Animation.Apply every update based on the time stored in TrackEntry, and advances that time based on Unity's Time.deltaTime
.
So if you don't store the TrackEntry when you call SetAnimation, you can retrieve it this way:
TrackEntry myTrackEntry = mySkeletonAnimation.state.GetCurrent(myTrackNumber); // can return null. always have a null guard before doing stuff.
At any point then, you can say
myTrackEntry.time = timeIWantToJumpTo;
And if you want it to stop but still keep applying (ie, not remove the TrackEntry from the track)
myTrackEntry.timeScale = 0f;
// timeScale is used to slow down or speed up a specific animation playback instance.
// It won't work with negative numbers.
// But 0 will cause it to pause until you set it to 1 again.
So a helper method would look like this:
public static Spine.TrackEntry JumpToTime (SkeletonAnimation skeletonAnimation, int trackNumber, float time, bool skipEvents, bool stop) {
if (skeletonAnimation == null) return null;
return JumpToTime(skeletonAnimation.state.GetCurrent(trackNumber), time, skipEvents, stop);
}
public static Spine.TrackEntry JumpToTime (Spine.TrackEntry trackEntry, float time, bool skipEvents, bool stop) {
if (trackEntry == null) return trackEntry;
trackEntry.time = time;
if (skipEvents)
trackEntry.lastTime = time;
if (stop)
trackEntry.timeScale = 0;
return trackEntry;
}
28 Jan 2016 6:29 pm
Full documentation of the runtimes in general is here: http://esotericsoftware.com/spine-using-runtimes
It's helpful for low-level stuff.
The spine-unity documentation I originally linked is for Unity-specific things. https://github.com/pharan/spine-unity-docs/