diff --git a/spine-unity/Assets/spine-unity/SkeletonAnimator.cs b/spine-unity/Assets/spine-unity/SkeletonAnimator.cs index 05e6359d6..695c63238 100644 --- a/spine-unity/Assets/spine-unity/SkeletonAnimator.cs +++ b/spine-unity/Assets/spine-unity/SkeletonAnimator.cs @@ -142,12 +142,12 @@ namespace Spine.Unity { // Always use Mix instead of Applying the first non-zero weighted clip. for (int c = 0; c < clipInfo.Length; c++) { var info = clipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) continue; - animationTable[NameHashCode(info.clip)].Apply(skeleton, 0, AnimationTime(stateInfo.normalizedTime, info.clip.length, stateInfo.loop), stateInfo.loop, null, weight, false, false); + animationTable[NameHashCode(info.clip)].Apply(skeleton, 0, AnimationTime(stateInfo.normalizedTime, info.clip.length, stateInfo.loop, stateInfo.speed <0), stateInfo.loop, null, weight, false, false); } if (hasNext) { for (int c = 0; c < nextClipInfo.Length; c++) { var info = nextClipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) continue; - animationTable[NameHashCode(info.clip)].Apply(skeleton, 0, nextStateInfo.normalizedTime * info.clip.length, nextStateInfo.loop, null, weight, false, false); + animationTable[NameHashCode(info.clip)].Apply(skeleton, 0, AnimationTime(nextStateInfo.normalizedTime , info.clip.length,nextStateInfo.speed < 0), nextStateInfo.loop, null, weight, false, false); } } } else { // case MixNext || SpineStyle @@ -155,13 +155,13 @@ namespace Spine.Unity { int c = 0; for (; c < clipInfo.Length; c++) { var info = clipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) continue; - animationTable[NameHashCode(info.clip)].Apply(skeleton, 0, AnimationTime(stateInfo.normalizedTime, info.clip.length, stateInfo.loop), stateInfo.loop, null, 1f, false, false); + animationTable[NameHashCode(info.clip)].Apply(skeleton, 0, AnimationTime(stateInfo.normalizedTime, info.clip.length, stateInfo.loop, stateInfo.speed <0), stateInfo.loop, null, 1f, false, false); break; } // Mix the rest for (; c < clipInfo.Length; c++) { var info = clipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) continue; - animationTable[NameHashCode(info.clip)].Apply(skeleton, 0, AnimationTime(stateInfo.normalizedTime, info.clip.length, stateInfo.loop), stateInfo.loop, null, weight, false, false); + animationTable[NameHashCode(info.clip)].Apply(skeleton, 0, AnimationTime(stateInfo.normalizedTime, info.clip.length, stateInfo.loop, stateInfo.speed <0), stateInfo.loop, null, weight, false, false); } c = 0; @@ -170,14 +170,14 @@ namespace Spine.Unity { if (mode == MixMode.SpineStyle) { for (; c < nextClipInfo.Length; c++) { var info = nextClipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) continue; - animationTable[NameHashCode(info.clip)].Apply(skeleton, 0, nextStateInfo.normalizedTime * info.clip.length, nextStateInfo.loop, null, 1f, false, false); + animationTable[NameHashCode(info.clip)].Apply(skeleton, 0, AnimationTime(nextStateInfo.normalizedTime , info.clip.length,nextStateInfo.speed < 0), nextStateInfo.loop, null, 1f, false, false); break; } } // Mix the rest for (; c < nextClipInfo.Length; c++) { var info = nextClipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) continue; - animationTable[NameHashCode(info.clip)].Apply(skeleton, 0, nextStateInfo.normalizedTime * info.clip.length, nextStateInfo.loop, null, weight, false, false); + animationTable[NameHashCode(info.clip)].Apply(skeleton, 0, AnimationTime(nextStateInfo.normalizedTime , info.clip.length,nextStateInfo.speed < 0), nextStateInfo.loop, null, weight, false, false); } } } @@ -200,13 +200,24 @@ namespace Spine.Unity { } } - static float AnimationTime (float normalizedTime, float clipLength, bool loop) { + static float AnimationTime (float normalizedTime, float clipLength, bool loop, bool reversed) { + if(reversed){ + normalizedTime = (1-normalizedTime+(int)normalizedTime) + (int)normalizedTime; + } float time = normalizedTime * clipLength; 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) { + if(reversed){ + normalizedTime = (1-normalizedTime+(int)normalizedTime) + (int)normalizedTime; + } + + return normalizedTime * clipLength; + } + int NameHashCode (AnimationClip clip) { int clipNameHashCode; if (!clipNameHashCodeTable.TryGetValue(clip, out clipNameHashCode)) {