You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.0 KiB
79 lines
2.0 KiB
using Spine; |
|
using Spine.Unity; |
|
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
using UnityEngine.Events; |
|
using UnityEngine.Serialization; |
|
|
|
public class SpineAnimtionPlay : MonoBehaviour |
|
{ |
|
[System.Serializable] |
|
public class Control |
|
{ |
|
[Space(10)] |
|
public int layer; |
|
[SpineAnimation] |
|
public string name; |
|
public bool loop; |
|
[Space] |
|
public float timeScale = 1f; |
|
[Space] |
|
public bool useMixDuration; |
|
public float mixDuration; |
|
|
|
[Space(10)] |
|
public bool USE_END = false; |
|
[System.Serializable] |
|
public class EndEvent : UnityEvent<bool> { } |
|
[FormerlySerializedAs("onEnd")] |
|
[SerializeField] |
|
[Space(10)] |
|
private EndEvent onEnd = new EndEvent(); |
|
public void PlayEnd() |
|
{ |
|
onEnd.Invoke(true); |
|
} |
|
} |
|
|
|
public SkeletonAnimation skeletonAnimation; |
|
[Space(10)] |
|
public List<Control> data; |
|
Spine.AnimationState spineState; |
|
public void Play(int idx) |
|
{ |
|
Play(data[idx]); |
|
} |
|
public void Play(Control control) |
|
{ |
|
if (spineState == null) |
|
spineState = skeletonAnimation.state; |
|
|
|
TrackEntry track = spineState.SetAnimation(control.layer, control.name, control.loop); |
|
|
|
if (track != null) |
|
{ |
|
if (control != null) |
|
{ |
|
track.MixDuration = control.useMixDuration ? control.mixDuration : 0; |
|
track.TimeScale = control.timeScale; |
|
} |
|
|
|
if (control.USE_END) |
|
{ |
|
track.Complete += delegate (TrackEntry entry) |
|
{ |
|
control.PlayEnd(); |
|
}; |
|
} |
|
|
|
//if (OnEvent != null) |
|
//{ |
|
// track.Event += delegate (TrackEntry trackEntry, Spine.Event e) |
|
// { |
|
// OnEvent(e); |
|
// }; |
|
//} |
|
} |
|
} |
|
}
|
|
|