Skip to content

Commit

Permalink
[unity] Fixed SkeletonMecanim incorrect looping playback of reversed …
Browse files Browse the repository at this point in the history
…non-looping clip. Closes #2165.
  • Loading branch information
HaraldCsaszar committed Sep 30, 2022
1 parent 5d18526 commit 114852b
Showing 1 changed file with 4 additions and 5 deletions.
Expand Up @@ -263,7 +263,6 @@ protected class ClipInfos {
var clip = GetAnimation(info.clip);
if (clip == null)
return false;

var time = AnimationTime(stateInfo.normalizedTime, info.clip.length,
info.clip.isLooping, stateInfo.speed < 0);
weight = useClipWeight1 ? layerWeight : weight;
Expand All @@ -289,7 +288,7 @@ protected class ClipInfos {
return false;

var time = AnimationTime(stateInfo.normalizedTime + interruptingClipTimeAddition,
info.clip.length, stateInfo.speed < 0);
info.clip.length, info.clip.isLooping, stateInfo.speed < 0);
weight = useClipWeight1 ? layerWeight : weight;
clip.Apply(skeleton, 0, time, info.clip.isLooping, null,
weight, layerBlendMode, MixDirection.In);
Expand Down Expand Up @@ -502,17 +501,17 @@ protected class ClipInfos {
}

static float AnimationTime (float normalizedTime, float clipLength, bool loop, bool reversed) {
float time = AnimationTime(normalizedTime, clipLength, reversed);
float time = ToSpineAnimationTime(normalizedTime, clipLength, loop, reversed);
if (loop) return time;
const float EndSnapEpsilon = 1f / 30f; // Workaround for end-duration keys not being applied.
return (clipLength - time < EndSnapEpsilon) ? clipLength : time; // return a time snapped to clipLength;
}

static float AnimationTime (float normalizedTime, float clipLength, bool reversed) {
static float ToSpineAnimationTime (float normalizedTime, float clipLength, bool loop, bool reversed) {
if (reversed)
normalizedTime = (1 - normalizedTime);
if (normalizedTime < 0.0f)
normalizedTime = (normalizedTime % 1.0f) + 1.0f;
normalizedTime = loop ? (normalizedTime % 1.0f) + 1.0f : 0.0f;
return normalizedTime * clipLength;
}

Expand Down

0 comments on commit 114852b

Please sign in to comment.