diff --git a/spine-tk2d/Assets/Spine/Editor/SkeletonAnimationInspector.cs b/spine-tk2d/Assets/Spine/Editor/SkeletonAnimationInspector.cs index 9c13c479e..94a7aa744 100644 --- a/spine-tk2d/Assets/Spine/Editor/SkeletonAnimationInspector.cs +++ b/spine-tk2d/Assets/Spine/Editor/SkeletonAnimationInspector.cs @@ -42,7 +42,7 @@ public class SkeletonAnimationInspector : Editor { void OnEnable () { skeletonDataAsset = serializedObject.FindProperty("skeletonDataAsset"); - animationName = serializedObject.FindProperty("animationName"); + animationName = serializedObject.FindProperty("_animationName"); loop = serializedObject.FindProperty("loop"); useAnimationName = serializedObject.FindProperty("useAnimationName"); initialSkinName = serializedObject.FindProperty("initialSkinName"); @@ -53,7 +53,7 @@ public class SkeletonAnimationInspector : Editor { override public void OnInspectorGUI () { serializedObject.Update(); - SkeletonComponent component = (SkeletonComponent)target; + SkeletonAnimation component = (SkeletonAnimation)target; EditorGUIUtility.LookLikeInspector(); EditorGUILayout.PropertyField(skeletonDataAsset); @@ -98,13 +98,13 @@ public class SkeletonAnimationInspector : Editor { EditorGUILayout.EndHorizontal(); if (animationIndex == 0) { - animationName.stringValue = null; + component.animationName = null; useAnimationName.boolValue = false; } else if (animationIndex == 1) { - animationName.stringValue = null; + component.animationName = null; useAnimationName.boolValue = true; } else { - animationName.stringValue = animations[animationIndex]; + component.animationName = animations[animationIndex]; useAnimationName.boolValue = true; } } diff --git a/spine-tk2d/Assets/Spine/SkeletonAnimation.cs b/spine-tk2d/Assets/Spine/SkeletonAnimation.cs index 35ee6a1d7..d4139ed85 100644 --- a/spine-tk2d/Assets/Spine/SkeletonAnimation.cs +++ b/spine-tk2d/Assets/Spine/SkeletonAnimation.cs @@ -40,31 +40,34 @@ using Spine; [ExecuteInEditMode, RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))] public class SkeletonAnimation : SkeletonComponent { public bool useAnimationName; - public String animationName; public bool loop; public Spine.AnimationState state; - + + public String _animationName; + public String animationName { + get { + TrackEntry entry = state.GetCurrent(0); + return entry == null ? null : entry.Animation.Name; + } + set { + if (!useAnimationName) return; + if (_animationName == value) return; + _animationName = value; + if (value == null) + state.ClearTrack(0); + else + state.SetAnimation(0, value, loop); + } + } + override public void Initialize () { base.Initialize(); // Call overridden method to initialize the skeleton. state = new Spine.AnimationState(skeletonDataAsset.GetAnimationStateData()); + if (_animationName != null) state.SetAnimation(0, _animationName, loop); } override public void UpdateSkeleton () { - if (useAnimationName) { - // Keep AnimationState in sync with animationName and loop fields. - TrackEntry entry = state.GetCurrent(0); - if (animationName == null || animationName.Length == 0) { - if (entry != null && entry.Animation != null) - state.ClearTrack(0); - } else if (entry == null || entry.Animation == null || animationName != entry.Animation.Name) { - Spine.Animation animation = skeleton.Data.FindAnimation(animationName); - if (animation != null) - state.SetAnimation(0, animation, loop); - } else if (entry != null) - entry.Loop = loop; - } - // Apply the animation. state.Update(Time.deltaTime * timeScale); state.Apply(skeleton); diff --git a/spine-unity/Assets/Spine/Editor/SkeletonAnimationInspector.cs b/spine-unity/Assets/Spine/Editor/SkeletonAnimationInspector.cs index 9c13c479e..94a7aa744 100644 --- a/spine-unity/Assets/Spine/Editor/SkeletonAnimationInspector.cs +++ b/spine-unity/Assets/Spine/Editor/SkeletonAnimationInspector.cs @@ -42,7 +42,7 @@ public class SkeletonAnimationInspector : Editor { void OnEnable () { skeletonDataAsset = serializedObject.FindProperty("skeletonDataAsset"); - animationName = serializedObject.FindProperty("animationName"); + animationName = serializedObject.FindProperty("_animationName"); loop = serializedObject.FindProperty("loop"); useAnimationName = serializedObject.FindProperty("useAnimationName"); initialSkinName = serializedObject.FindProperty("initialSkinName"); @@ -53,7 +53,7 @@ public class SkeletonAnimationInspector : Editor { override public void OnInspectorGUI () { serializedObject.Update(); - SkeletonComponent component = (SkeletonComponent)target; + SkeletonAnimation component = (SkeletonAnimation)target; EditorGUIUtility.LookLikeInspector(); EditorGUILayout.PropertyField(skeletonDataAsset); @@ -98,13 +98,13 @@ public class SkeletonAnimationInspector : Editor { EditorGUILayout.EndHorizontal(); if (animationIndex == 0) { - animationName.stringValue = null; + component.animationName = null; useAnimationName.boolValue = false; } else if (animationIndex == 1) { - animationName.stringValue = null; + component.animationName = null; useAnimationName.boolValue = true; } else { - animationName.stringValue = animations[animationIndex]; + component.animationName = animations[animationIndex]; useAnimationName.boolValue = true; } } diff --git a/spine-unity/Assets/Spine/SkeletonAnimation.cs b/spine-unity/Assets/Spine/SkeletonAnimation.cs index 35ee6a1d7..52c47c80e 100644 --- a/spine-unity/Assets/Spine/SkeletonAnimation.cs +++ b/spine-unity/Assets/Spine/SkeletonAnimation.cs @@ -40,31 +40,34 @@ using Spine; [ExecuteInEditMode, RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))] public class SkeletonAnimation : SkeletonComponent { public bool useAnimationName; - public String animationName; public bool loop; public Spine.AnimationState state; + public String _animationName; + public String animationName { + get { + TrackEntry entry = state.GetCurrent(0); + return entry == null ? null : entry.Animation.Name; + } + set { + if (!useAnimationName) return; + if (_animationName == value) return; + _animationName = value; + if (value == null) + state.ClearTrack(0); + else + state.SetAnimation(0, value, loop); + } + } + override public void Initialize () { base.Initialize(); // Call overridden method to initialize the skeleton. state = new Spine.AnimationState(skeletonDataAsset.GetAnimationStateData()); + if (_animationName != null) state.SetAnimation(0, _animationName, loop); } override public void UpdateSkeleton () { - if (useAnimationName) { - // Keep AnimationState in sync with animationName and loop fields. - TrackEntry entry = state.GetCurrent(0); - if (animationName == null || animationName.Length == 0) { - if (entry != null && entry.Animation != null) - state.ClearTrack(0); - } else if (entry == null || entry.Animation == null || animationName != entry.Animation.Name) { - Spine.Animation animation = skeleton.Data.FindAnimation(animationName); - if (animation != null) - state.SetAnimation(0, animation, loop); - } else if (entry != null) - entry.Loop = loop; - } - // Apply the animation. state.Update(Time.deltaTime * timeScale); state.Apply(skeleton);