From 114852b15cc22715ed5664d404de89d61c50e01f Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Fri, 30 Sep 2022 14:09:24 +0200 Subject: [PATCH] [unity] Fixed SkeletonMecanim incorrect looping playback of reversed non-looping clip. Closes #2165. --- .../Runtime/spine-unity/Components/SkeletonMecanim.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonMecanim.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonMecanim.cs index 2f29cf3dd..8c53527e4 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonMecanim.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonMecanim.cs @@ -263,7 +263,6 @@ namespace Spine.Unity { 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; @@ -289,7 +288,7 @@ namespace Spine.Unity { 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); @@ -502,17 +501,17 @@ namespace Spine.Unity { } 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; }