From 618e20dc9aa276344b2013fc0266e993983f6204 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Tue, 9 Nov 2021 20:05:08 +0100 Subject: [PATCH] [Unity] Fixed `Initial Flip` not updating mesh in Editor mode. Closes #1953. --- .../Components/SkeletonAnimationInspector.cs | 8 ----- .../Components/SkeletonRendererInspector.cs | 31 +++++++++++++++++++ 2 files changed, 31 insertions(+), 8 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 56ae78260..d0f3e0e10 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 @@ -38,7 +38,6 @@ namespace Spine.Unity.Editor { 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."); @@ -79,13 +78,6 @@ namespace Spine.Unity.Editor { SkeletonRootMotionParameter(); serializedObject.ApplyModifiedProperties(); - - if (!isInspectingPrefab) { - if (requireRepaint) { - UnityEditorInternal.InternalEditorUtility.RepaintAllViews(); - requireRepaint = false; - } - } } protected void TrySetAnimation (SkeletonAnimation skeletonAnimation) { 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 abff041fd..df4833c7c 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 @@ -70,6 +70,8 @@ namespace Spine.Unity.Editor { protected SerializedProperty maskInteraction; protected SerializedProperty maskMaterialsNone, maskMaterialsInside, maskMaterialsOutside; protected SpineInspectorUtility.SerializedSortingProperties sortingProperties; + protected bool wasInitParameterChanged = false; + protected bool requireRepaint = false; protected bool isInspectingPrefab; protected bool forceReloadQueued = false; @@ -196,6 +198,13 @@ namespace Spine.Unity.Editor { SceneView.RepaintAll(); } } + + if (!isInspectingPrefab) { + if (requireRepaint) { + UnityEditorInternal.InternalEditorUtility.RepaintAllViews(); + requireRepaint = false; + } + } } protected virtual void DrawInspectorGUI (bool multi) { @@ -259,6 +268,9 @@ namespace Spine.Unity.Editor { bool valid = TargetIsValid; + foreach (var o in targets) + ApplyModifiedMeshParameters(o as SkeletonRenderer); + // Fields. if (multi) { using (new EditorGUILayout.HorizontalScope(EditorStyles.helpBox)) { @@ -330,8 +342,10 @@ namespace Spine.Unity.Editor { using (new SpineInspectorUtility.IndentScope()) { using (new EditorGUILayout.HorizontalScope()) { + EditorGUI.BeginChangeCheck(); SpineInspectorUtility.ToggleLeftLayout(initialFlipX); SpineInspectorUtility.ToggleLeftLayout(initialFlipY); + wasInitParameterChanged |= EditorGUI.EndChangeCheck(); // Value used in the next update. EditorGUILayout.Space(); } @@ -421,6 +435,23 @@ namespace Spine.Unity.Editor { } } + protected void ApplyModifiedMeshParameters (SkeletonRenderer skeletonRenderer) { + if (skeletonRenderer == null) return; + if (!skeletonRenderer.valid) + return; + + if (!isInspectingPrefab) { + if (wasInitParameterChanged) { + wasInitParameterChanged = false; + if (!Application.isPlaying) { + skeletonRenderer.Initialize(true); + skeletonRenderer.LateUpdate(); + requireRepaint = true; + } + } + } + } + protected void SkeletonRootMotionParameter () { SkeletonRootMotionParameter(targets); }