From 0279c3a391a5fde989090af4d0aeff1dedde338c Mon Sep 17 00:00:00 2001 From: pharan Date: Mon, 26 Dec 2016 11:30:05 +0800 Subject: [PATCH] [unity] SkeletonAnimator deferred autoReset. --- .../Editor/SkeletonAnimatorInspector.cs | 6 ++++-- .../Assets/spine-unity/SkeletonAnimator.cs | 18 ++++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/spine-unity/Assets/spine-unity/Editor/SkeletonAnimatorInspector.cs b/spine-unity/Assets/spine-unity/Editor/SkeletonAnimatorInspector.cs index 8204cd800..42a618c6f 100644 --- a/spine-unity/Assets/spine-unity/Editor/SkeletonAnimatorInspector.cs +++ b/spine-unity/Assets/spine-unity/Editor/SkeletonAnimatorInspector.cs @@ -37,17 +37,19 @@ namespace Spine.Unity.Editor { [CanEditMultipleObjects] public class SkeletonAnimatorInspector : SkeletonRendererInspector { protected SerializedProperty layerMixModes; + protected SerializedProperty autoReset; + protected override void OnEnable () { base.OnEnable(); + autoReset = serializedObject.FindProperty("autoReset"); layerMixModes = serializedObject.FindProperty("layerMixModes"); } protected override void DrawInspectorGUI (bool multi) { base.DrawInspectorGUI(multi); + EditorGUILayout.PropertyField(autoReset); EditorGUILayout.PropertyField(layerMixModes, true); - if (!TargetIsValid) return; - if (!isInspectingPrefab) DrawSkeletonUtilityButton(multi); } diff --git a/spine-unity/Assets/spine-unity/SkeletonAnimator.cs b/spine-unity/Assets/spine-unity/SkeletonAnimator.cs index 76cfbc3f1..dce8bc22e 100644 --- a/spine-unity/Assets/spine-unity/SkeletonAnimator.cs +++ b/spine-unity/Assets/spine-unity/SkeletonAnimator.cs @@ -39,7 +39,9 @@ namespace Spine.Unity { public enum MixMode { AlwaysMix, MixNext, SpineStyle } public MixMode[] layerMixModes = new MixMode[0]; + public bool autoReset = false; + List previousAnimations = new List(); #region Bone Callbacks (ISkeletonAnimation) protected event UpdateBonesDelegate _UpdateLocal; @@ -92,6 +94,12 @@ namespace Spine.Unity { // Clear Previous if (autoReset) { + var previousAnimations = this.previousAnimations; + for (int i = 0, n = previousAnimations.Count; i < n; i++) { + previousAnimations[i].SetKeyedItemsToSetupPose(skeleton); + } + previousAnimations.Clear(); + for (int layer = 0, n = animator.layerCount; layer < n; layer++) { float layerWeight = animator.GetLayerWeight(layer); if (layerWeight <= 0) continue; @@ -109,13 +117,15 @@ namespace Spine.Unity { #endif 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)].SetKeyedItemsToSetupPose(skeleton); + var info = clipInfo[c]; + float weight = info.weight * layerWeight; if (weight == 0) continue; + previousAnimations.Add(animationTable[NameHashCode(info.clip)]); } 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)].SetKeyedItemsToSetupPose(skeleton); + var info = nextClipInfo[c]; + float weight = info.weight * layerWeight; if (weight == 0) continue; + previousAnimations.Add(animationTable[NameHashCode(info.clip)]); } } }