mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-17 04:21:39 +08:00
Fixed setting animation name without looping.
This commit is contained in:
parent
0fb51b3869
commit
52696c2607
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user