Skip to content

Commit

Permalink
[unity] Fixed SkeletonAnimation Inspector code causing incorrect anim…
Browse files Browse the repository at this point in the history
…ation playback. Closes #1841.
  • Loading branch information
HaraldCsaszar committed Feb 3, 2021
1 parent 8908cdd commit 511c05a
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace Spine.Unity.Editor {
[CanEditMultipleObjects]
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.");
Expand All @@ -60,9 +61,14 @@ public class SkeletonAnimationInspector : SkeletonRendererInspector {
if (!sameData) {
EditorGUILayout.DelayedTextField(animationName);
} else {
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(animationName);
wasAnimationParameterChanged |= EditorGUI.EndChangeCheck(); // Value used in the next update.
}

EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(loop, LoopLabel);
wasAnimationParameterChanged |= EditorGUI.EndChangeCheck(); // Value used in the next update.
EditorGUILayout.PropertyField(timeScale, TimeScaleLabel);
foreach (var o in targets) {
var component = o as SkeletonAnimation;
Expand All @@ -89,9 +95,12 @@ public class SkeletonAnimationInspector : SkeletonRendererInspector {

TrackEntry current = skeletonAnimation.AnimationState.GetCurrent(0);
if (!isInspectingPrefab) {
string activeAnimation = (current != null) ? current.Animation.Name : null;
bool wasAnimationNameChanged = activeAnimation != animationName.stringValue;
if (wasAnimationNameChanged) {
string activeAnimation = (current != null) ? current.Animation.Name : "";
bool activeLoop = (current != null) ? current.Loop : false;
bool animationParameterChanged = this.wasAnimationParameterChanged &&
((activeAnimation != animationName.stringValue) || (activeLoop != loop.boolValue));
if (animationParameterChanged) {
this.wasAnimationParameterChanged = false;
var skeleton = skeletonAnimation.Skeleton;
var state = skeletonAnimation.AnimationState;

Expand Down

0 comments on commit 511c05a

Please sign in to comment.