I've started evaluating Spine this morning,
and looping a segment of an animation is one of the things I need as well.
So I started looking at the method AnimationState.SetAnimation, it seemed at first easy to implement:
/// <summary>Set the current animation. Any queued animations are cleared.</summary>
public TrackEntry SetAnimation (int trackIndex, Animation animation, bool loop) {
if (animation == null) throw new ArgumentNullException("animation", "animation cannot be null.");
TrackEntry entry = new TrackEntry();
entry.animation = animation;
entry.loop = loop;
entry.time = 0;
entry.endTime = animation.Duration;
SetCurrent(trackIndex, entry);
return entry;
}
So I started adding an overload on SetAnimation, with time boundaries that would set the animation segment, with the following signature:
public TrackEntry SetAnimation(int trackIndex, Animation animation, bool loop, float startTime, float endTime)
And this was the beginning of dealing with quite a big mess :rock:
I had to add a startTime field on class TrackEntry.
After tweaking here and there, I finally got it working, (except when two animations are Mixing, I haven't tried there is probably a fix to add). So this is not a complete work yet, but it's start.
Please let me know if it's a good start =)
Here is the code changes attached
Note: I'm using Monogame, not unity, but these files are common