Skip to content

Instantly share code, notes, and snippets.

@pharan
Last active December 15, 2016 23:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pharan/a6726f69f7832b02b740c673c039ce7f to your computer and use it in GitHub Desktop.
Save pharan/a6726f69f7832b02b740c673c039ce7f to your computer and use it in GitHub Desktop.
Quick and dirty Spine.AnimationState SceneView debug. This logs the current state of the AnimationState tracks.
using UnityEngine;
using System.Text;
public class DEBUG_AnimationStateSceneView : MonoBehaviour {
public bool follow = true;
}
#if UNITY_EDITOR
namespace Spine.Unity.Debugger {
[UnityEditor.CustomEditor(typeof(DEBUG_AnimationStateSceneView))]
public class DEBUG_AnimationStateSceneViewEditor : UnityEditor.Editor {
IAnimationStateComponent skeletonAnimation;
ISkeletonComponent skeletonComponent;
DEBUG_AnimationStateSceneView component;
Transform transform;
Spine.AnimationState state;
void OnEnable () {
if (component == null) component = target as DEBUG_AnimationStateSceneView;
if (transform == null) transform = component.transform;
if (skeletonAnimation == null) skeletonAnimation = component.GetComponent<IAnimationStateComponent>();
if (skeletonAnimation != null) state = skeletonAnimation.AnimationState;
if (skeletonComponent == null) skeletonComponent = component.GetComponent<ISkeletonComponent>();
}
void OnSceneGUI () {
if (state == null) OnEnable();
if (state == null) return;
Vector3 labelPos = component.follow ? skeletonComponent.Skeleton.RootBone.GetWorldPosition(transform) : Vector3.zero;
GUIStyle labelStyle = UnityEditor.EditorStyles.whiteMiniLabel;
if (!Application.isPlaying) {
UnityEditor.Handles.Label(labelPos, "Switch to PLAY MODE to debug Spine.AnimationState.", labelStyle);
return;
}
var sb = new StringBuilder();
const string format = "##.00";
const string looping = "(\u21bb)";
bool mixing = false;
var stateTracks = state.Tracks;
var stateTracksItems = stateTracks.Items;
for (int i = 0, n = state.Tracks.Count; i < n; i++) {
var trackEntry = stateTracksItems[i];
if (trackEntry == null) continue;
sb.AppendFormat("Track {0}:\n-------------------------\n", i);
TrackEntry previous = trackEntry.MixingFrom;
while (previous != null) {
sb.Append(previous.Animation.Name);
if (previous.Loop) sb.Append(looping);
sb.Append("->");
previous = previous.MixingFrom;
mixing = true;
}
sb.Append(trackEntry.Animation.Name);
if (trackEntry.Loop) sb.Append(looping);
TrackEntry next = trackEntry.Next;
while (next != null) {
sb.Append("->");
sb.Append(next.Animation.Name);
if (next.Loop) sb.Append(looping);
next = next.Next;
}
sb.AppendFormat(
"\ntrack:{0} animation:{1}",
trackEntry.TrackTime.ToString(format),
trackEntry.AnimationTime.ToString(format)
);
if (mixing) {
sb.AppendFormat("\nmix:{0} mixduration:{1} mixPercent:{2}",
trackEntry.MixTime.ToString(format),
trackEntry.MixDuration.ToString(format),
(trackEntry.MixTime/trackEntry.MixDuration).ToString(format)
);
}
sb.Append("\n");
}
UnityEditor.Handles.Label(labelPos, sb.ToString(), labelStyle);
}
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment