From 110581abeacef1b4eacb7d8b88d76af3f046fa1c Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Thu, 21 Jan 2021 13:07:02 +0100 Subject: [PATCH] [unity] Changing AnimationName in the SkeletonAnimation Inspector now updates every time. Now also repaints GameView accordingly, for both animation and skin changes. Closes #1832. --- .../Components/SkeletonAnimationInspector.cs | 18 +++++++++--------- .../Components/SkeletonRendererInspector.cs | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonAnimationInspector.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonAnimationInspector.cs index c87ee6262..ac91bd41f 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonAnimationInspector.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonAnimationInspector.cs @@ -37,7 +37,6 @@ namespace Spine.Unity.Editor { [CanEditMultipleObjects] public class SkeletonAnimationInspector : SkeletonRendererInspector { protected SerializedProperty animationName, loop, timeScale, autoReset; - protected bool wasAnimationNameChanged; 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."); @@ -55,16 +54,13 @@ namespace Spine.Unity.Editor { bool sameData = SpineInspectorUtility.TargetsUseSameData(serializedObject); foreach (var o in targets) - TrySetAnimation(o as SkeletonAnimation, multi); - wasAnimationNameChanged = false; + TrySetAnimation(o as SkeletonAnimation); EditorGUILayout.Space(); if (!sameData) { EditorGUILayout.DelayedTextField(animationName); } else { - EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(animationName); - wasAnimationNameChanged |= EditorGUI.EndChangeCheck(); // Value used in the next update. } EditorGUILayout.PropertyField(loop, LoopLabel); EditorGUILayout.PropertyField(timeScale, TimeScaleLabel); @@ -76,20 +72,25 @@ namespace Spine.Unity.Editor { EditorGUILayout.Space(); SkeletonRootMotionParameter(); + serializedObject.ApplyModifiedProperties(); + if (!isInspectingPrefab) { if (requireRepaint) { - SceneView.RepaintAll(); + UnityEditorInternal.InternalEditorUtility.RepaintAllViews(); requireRepaint = false; } } } - protected void TrySetAnimation (SkeletonAnimation skeletonAnimation, bool multi) { + protected void TrySetAnimation (SkeletonAnimation skeletonAnimation) { if (skeletonAnimation == null) return; if (!skeletonAnimation.valid) return; + TrackEntry current = skeletonAnimation.AnimationState.GetCurrent(0); if (!isInspectingPrefab) { + string activeAnimation = (current != null) ? current.Animation.Name : null; + bool wasAnimationNameChanged = activeAnimation != animationName.stringValue; if (wasAnimationNameChanged) { var skeleton = skeletonAnimation.Skeleton; var state = skeletonAnimation.AnimationState; @@ -105,7 +106,7 @@ namespace Spine.Unity.Editor { if (animationToUse != null) { skeletonAnimation.AnimationState.SetAnimation(0, animationToUse, loop.boolValue); } - skeleton.UpdateWorldTransform(); + skeletonAnimation.Update(0); skeletonAnimation.LateUpdate(); requireRepaint = true; } else { @@ -118,7 +119,6 @@ namespace Spine.Unity.Editor { // Reflect animationName serialized property in the inspector even if SetAnimation API was used. if (Application.isPlaying) { - TrackEntry current = skeletonAnimation.AnimationState.GetCurrent(0); if (current != null) { if (skeletonAnimation.AnimationName != animationName.stringValue) animationName.stringValue = current.Animation.Name; diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonRendererInspector.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonRendererInspector.cs index 2bb52f43d..d66869120 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonRendererInspector.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonRendererInspector.cs @@ -530,7 +530,7 @@ namespace Spine.Unity.Editor { if (mismatchDetected) { mismatchDetected = false; - SceneView.RepaintAll(); + UnityEditorInternal.InternalEditorUtility.RepaintAllViews(); } } }