mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-26 19:51:47 +08:00
[unity] Handle SkeletonData inspector play-pause.
Fixes https://github.com/EsotericSoftware/spine-runtimes/issues/996
This commit is contained in:
parent
f40efe6066
commit
6eb3f1dbd7
@ -378,8 +378,7 @@ namespace Spine.Unity.Editor {
|
|||||||
|
|
||||||
if (m_skeletonAnimation != null && m_skeletonAnimation.state != null) {
|
if (m_skeletonAnimation != null && m_skeletonAnimation.state != null) {
|
||||||
if (GUILayout.Button(SpineInspectorUtility.TempContent("Setup Pose", Icons.skeleton), GUILayout.Width(105), GUILayout.Height(18))) {
|
if (GUILayout.Button(SpineInspectorUtility.TempContent("Setup Pose", Icons.skeleton), GUILayout.Width(105), GUILayout.Height(18))) {
|
||||||
StopAnimation();
|
ClearAnimationSetupPose();
|
||||||
m_skeletonAnimation.skeleton.SetToSetupPose();
|
|
||||||
m_requireRefresh = true;
|
m_requireRefresh = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -394,14 +393,10 @@ namespace Spine.Unity.Editor {
|
|||||||
using (new GUILayout.HorizontalScope()) {
|
using (new GUILayout.HorizontalScope()) {
|
||||||
if (m_skeletonAnimation != null && m_skeletonAnimation.state != null) {
|
if (m_skeletonAnimation != null && m_skeletonAnimation.state != null) {
|
||||||
var activeTrack = m_skeletonAnimation.state.GetCurrent(0);
|
var activeTrack = m_skeletonAnimation.state.GetCurrent(0);
|
||||||
if (activeTrack != null && activeTrack.Animation == animation) {
|
bool active = activeTrack != null && activeTrack.Animation == animation;
|
||||||
if (GUILayout.Button("\u25BA", activePlayButtonStyle, GUILayout.Width(24))) {
|
//bool sameAndPlaying = active && activeTrack.TimeScale > 0f;
|
||||||
StopAnimation();
|
if (GUILayout.Button("\u25BA", active ? activePlayButtonStyle : idlePlayButtonStyle, GUILayout.Width(24))) {
|
||||||
}
|
PlayPauseAnimation(animation.Name, true);
|
||||||
} else {
|
|
||||||
if (GUILayout.Button("\u25BA", idlePlayButtonStyle, GUILayout.Width(24))) {
|
|
||||||
PlayAnimation(animation.Name, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
GUILayout.Label("-", GUILayout.Width(24));
|
GUILayout.Label("-", GUILayout.Width(24));
|
||||||
@ -555,36 +550,62 @@ namespace Spine.Unity.Editor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void StopAnimation () {
|
void ClearAnimationSetupPose () {
|
||||||
if (m_skeletonAnimation == null) {
|
if (m_skeletonAnimation == null) {
|
||||||
Debug.LogWarning("Animation was stopped but preview doesn't exist. It's possible that the Preview Panel is closed.");
|
Debug.LogWarning("Animation was stopped but preview doesn't exist. It's possible that the Preview Panel is closed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
m_skeletonAnimation.state.ClearTrack(0);
|
m_skeletonAnimation.AnimationState.ClearTracks();
|
||||||
m_playing = false;
|
m_skeletonAnimation.Skeleton.SetToSetupPose();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Spine.Event> m_animEvents = new List<Spine.Event>();
|
List<Spine.Event> m_animEvents = new List<Spine.Event>();
|
||||||
List<float> m_animEventFrames = new List<float>();
|
List<float> m_animEventFrames = new List<float>();
|
||||||
|
|
||||||
void PlayAnimation (string animName, bool loop) {
|
void PlayPauseAnimation (string animationName, bool loop) {
|
||||||
m_animEvents.Clear();
|
if (m_skeletonAnimation == null) {
|
||||||
m_animEventFrames.Clear();
|
Debug.LogWarning("Animation was stopped but preview doesn't exist. It's possible that the Preview Panel is closed.");
|
||||||
|
}
|
||||||
m_skeletonAnimation.state.SetAnimation(0, animName, loop);
|
|
||||||
|
var targetAnimation = m_skeletonData.FindAnimation(animationName);
|
||||||
Spine.Animation a = m_skeletonAnimation.state.GetCurrent(0).Animation;
|
if (targetAnimation != null) {
|
||||||
foreach (Timeline t in a.Timelines) {
|
var currentTrack = m_skeletonAnimation.AnimationState.GetCurrent(0);
|
||||||
if (t.GetType() == typeof(EventTimeline)) {
|
bool isEmpty = (currentTrack == null);
|
||||||
var et = (EventTimeline)t;
|
bool isNewAnimation = isEmpty || currentTrack.Animation != targetAnimation;
|
||||||
for (int i = 0; i < et.Events.Length; i++) {
|
|
||||||
m_animEvents.Add(et.Events[i]);
|
if (isEmpty) {
|
||||||
m_animEventFrames.Add(et.Frames[i]);
|
m_skeletonAnimation.Skeleton.SetToSetupPose();
|
||||||
}
|
m_skeletonAnimation.AnimationState.SetAnimation(0, targetAnimation, loop);
|
||||||
}
|
} else {
|
||||||
|
var sameAnimation = (currentTrack.Animation == targetAnimation);
|
||||||
|
if (sameAnimation) {
|
||||||
|
currentTrack.TimeScale = (currentTrack.TimeScale == 0) ? 1f : 0f; // pause/play
|
||||||
|
} else {
|
||||||
|
currentTrack.TimeScale = 1f;
|
||||||
|
m_skeletonAnimation.AnimationState.SetAnimation(0, targetAnimation, loop);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isNewAnimation) {
|
||||||
|
m_animEvents.Clear();
|
||||||
|
m_animEventFrames.Clear();
|
||||||
|
foreach (Timeline timeline in targetAnimation.Timelines) {
|
||||||
|
var eventTimeline = timeline as EventTimeline;
|
||||||
|
if (eventTimeline != null) {
|
||||||
|
for (int i = 0; i < eventTimeline.Events.Length; i++) {
|
||||||
|
m_animEvents.Add(eventTimeline.Events[i]);
|
||||||
|
m_animEventFrames.Add(eventTimeline.Frames[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
currentTrack = m_skeletonAnimation.AnimationState.GetCurrent(0); // currentTrack may have changed when new animation was set.
|
||||||
|
m_playing = currentTrack.TimeScale > 0;
|
||||||
|
} else {
|
||||||
|
Debug.LogFormat("Something went wrong. The Spine.Animation named '{0}' was not found.", animationName);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_playing = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitPreview () {
|
void InitPreview () {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user