Browse Source

[unity] Fixed SkeletonMecanim handling negative NormalizedTime incorrectly. Closes #1790.

Harald Csaszar 4 years ago
parent
commit
17e8373e47

+ 8 - 9
spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonMecanim.cs

@@ -228,7 +228,7 @@ namespace Spine.Unity {
 					return false;
 
 				var time = AnimationTime(stateInfo.normalizedTime, info.clip.length,
-										info.clip.isLooping, stateInfo.speed < 0);
+										info.clip.isLooping);
 				weight = useClipWeight1 ? layerWeight : weight;
 				clip.Apply(skeleton, 0, time, info.clip.isLooping, null,
 						weight, layerBlendMode, MixDirection.In);
@@ -252,7 +252,7 @@ namespace Spine.Unity {
 					return false;
 
 				var time = AnimationTime(stateInfo.normalizedTime + interruptingClipTimeAddition,
-										info.clip.length, stateInfo.speed < 0);
+										info.clip.length);
 				weight = useClipWeight1 ? layerWeight : weight;
 				clip.Apply(skeleton, 0, time, info.clip.isLooping, null,
 							weight, layerBlendMode, MixDirection.In);
@@ -462,21 +462,20 @@ namespace Spine.Unity {
 				}
 				animation = GetAnimation(clip);
 				float time = AnimationTime(stateInfo.normalizedTime, clip.length,
-										clip.isLooping, stateInfo.speed < 0);
+										clip.isLooping);
 				return new KeyValuePair<Animation, float>(animation, time);
 			}
 
-			static float AnimationTime (float normalizedTime, float clipLength, bool loop, bool reversed) {
-				float time = AnimationTime(normalizedTime, clipLength, reversed);
+			static float AnimationTime (float normalizedTime, float clipLength, bool loop) {
+				float time = AnimationTime(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;
-
+			static float AnimationTime (float normalizedTime, float clipLength) {
+				if (normalizedTime < 0.0f)
+					normalizedTime = (normalizedTime % 1.0f) + 1.0f;
 				return normalizedTime * clipLength;
 			}