Browse Source

[unity] Fixed SkeletonAnimation Inspector code causing incorrect animation playback. Closes #1841.

Harald Csaszar 4 years ago
parent
commit
511c05a3c7

+ 12 - 3
spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonAnimationInspector.cs

@@ -37,6 +37,7 @@ namespace Spine.Unity.Editor {
 	[CanEditMultipleObjects]
 	public class SkeletonAnimationInspector : SkeletonRendererInspector {
 		protected SerializedProperty animationName, loop, timeScale, autoReset;
+		protected bool wasAnimationParameterChanged = false;
 		protected bool requireRepaint;
 		readonly GUIContent LoopLabel = new GUIContent("Loop", "Whether or not .AnimationName should loop. This only applies to the initial animation specified in the inspector, or any subsequent Animations played through .AnimationName. Animations set through state.SetAnimation are unaffected.");
 		readonly GUIContent TimeScaleLabel = new GUIContent("Time Scale", "The rate at which animations progress over time. 1 means normal speed. 0.5 means 50% speed.");
@@ -60,9 +61,14 @@ namespace Spine.Unity.Editor {
 			if (!sameData) {
 				EditorGUILayout.DelayedTextField(animationName);
 			} else {
+				EditorGUI.BeginChangeCheck();
 				EditorGUILayout.PropertyField(animationName);
+				wasAnimationParameterChanged |= EditorGUI.EndChangeCheck(); // Value used in the next update.
 			}
+
+			EditorGUI.BeginChangeCheck();
 			EditorGUILayout.PropertyField(loop, LoopLabel);
+			wasAnimationParameterChanged |= EditorGUI.EndChangeCheck(); // Value used in the next update.
 			EditorGUILayout.PropertyField(timeScale, TimeScaleLabel);
 			foreach (var o in targets) {
 				var component = o as SkeletonAnimation;
@@ -89,9 +95,12 @@ namespace Spine.Unity.Editor {
 
 			TrackEntry current = skeletonAnimation.AnimationState.GetCurrent(0);
 			if (!isInspectingPrefab) {
-				string activeAnimation = (current != null) ? current.Animation.Name : null;
-				bool wasAnimationNameChanged = activeAnimation != animationName.stringValue;
-				if (wasAnimationNameChanged) {
+				string activeAnimation = (current != null) ? current.Animation.Name : "";
+				bool activeLoop = (current != null) ? current.Loop : false;
+				bool animationParameterChanged = this.wasAnimationParameterChanged &&
+					((activeAnimation != animationName.stringValue) || (activeLoop != loop.boolValue));
+				if (animationParameterChanged) {
+					this.wasAnimationParameterChanged = false;
 					var skeleton = skeletonAnimation.Skeleton;
 					var state = skeletonAnimation.AnimationState;