mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-25 22:23:42 +08:00
Better AnimationState event delegates.
This commit is contained in:
parent
8506ed5154
commit
4216077c0e
@ -40,13 +40,15 @@ namespace Spine {
|
|||||||
public AnimationStateData Data { get { return data; } }
|
public AnimationStateData Data { get { return data; } }
|
||||||
public float TimeScale { get { return timeScale; } set { timeScale = value; } }
|
public float TimeScale { get { return timeScale; } set { timeScale = value; } }
|
||||||
|
|
||||||
/// <summary>The list of tracks that have animations, which may contain nulls.</summary>
|
public delegate void StartEndDelegate(AnimationState state, int trackIndex);
|
||||||
public List<TrackEntry> Tracks { get { return tracks; } }
|
public StartEndDelegate Start;
|
||||||
|
public StartEndDelegate End;
|
||||||
|
|
||||||
public event EventHandler<StartEndArgs> Start;
|
public delegate void EventDelegate(AnimationState state, int trackIndex, Event e);
|
||||||
public event EventHandler<StartEndArgs> End;
|
public EventDelegate Event;
|
||||||
public event EventHandler<EventTriggeredArgs> Event;
|
|
||||||
public event EventHandler<CompleteArgs> Complete;
|
public delegate void CompleteDelete(AnimationState state, int trackIndex, int loopCount);
|
||||||
|
public CompleteDelete Complete;
|
||||||
|
|
||||||
public AnimationState (AnimationStateData data) {
|
public AnimationState (AnimationStateData data) {
|
||||||
if (data == null) throw new ArgumentNullException("data cannot be null.");
|
if (data == null) throw new ArgumentNullException("data cannot be null.");
|
||||||
@ -73,7 +75,7 @@ namespace Spine {
|
|||||||
if (current.loop ? (current.lastTime % endTime > time % endTime) : (current.lastTime < endTime && time >= endTime)) {
|
if (current.loop ? (current.lastTime % endTime > time % endTime) : (current.lastTime < endTime && time >= endTime)) {
|
||||||
int count = (int)(time / endTime);
|
int count = (int)(time / endTime);
|
||||||
current.OnComplete(this, i, count);
|
current.OnComplete(this, i, count);
|
||||||
if (Complete != null) Complete(this, new CompleteArgs(i, count));
|
if (Complete != null) Complete(this, i, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
TrackEntry next = current.next;
|
TrackEntry next = current.next;
|
||||||
@ -118,7 +120,7 @@ namespace Spine {
|
|||||||
for (int ii = 0, nn = events.Count; ii < nn; ii++) {
|
for (int ii = 0, nn = events.Count; ii < nn; ii++) {
|
||||||
Event e = events[ii];
|
Event e = events[ii];
|
||||||
current.OnEvent(this, i, e);
|
current.OnEvent(this, i, e);
|
||||||
if (Event != null) Event(this, new EventTriggeredArgs(i, e));
|
if (Event != null) Event(this, i, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
current.lastTime = current.time;
|
current.lastTime = current.time;
|
||||||
@ -137,7 +139,7 @@ namespace Spine {
|
|||||||
if (current == null) return;
|
if (current == null) return;
|
||||||
|
|
||||||
current.OnEnd(this, trackIndex);
|
current.OnEnd(this, trackIndex);
|
||||||
if (End != null) End(this, new StartEndArgs(trackIndex));
|
if (End != null) End(this, trackIndex);
|
||||||
|
|
||||||
tracks[trackIndex] = null;
|
tracks[trackIndex] = null;
|
||||||
}
|
}
|
||||||
@ -156,7 +158,7 @@ namespace Spine {
|
|||||||
current.previous = null;
|
current.previous = null;
|
||||||
|
|
||||||
current.OnEnd(this, index);
|
current.OnEnd(this, index);
|
||||||
if (End != null) End(this, new StartEndArgs(index));
|
if (End != null) End(this, index);
|
||||||
|
|
||||||
entry.mixDuration = data.GetMix(current.animation, entry.animation);
|
entry.mixDuration = data.GetMix(current.animation, entry.animation);
|
||||||
if (entry.mixDuration > 0) {
|
if (entry.mixDuration > 0) {
|
||||||
@ -172,7 +174,7 @@ namespace Spine {
|
|||||||
tracks[index] = entry;
|
tracks[index] = entry;
|
||||||
|
|
||||||
entry.OnStart(this, index);
|
entry.OnStart(this, index);
|
||||||
if (Start != null) Start(this, new StartEndArgs(index));
|
if (Start != null) Start(this, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TrackEntry SetAnimation (int trackIndex, String animationName, bool loop) {
|
public TrackEntry SetAnimation (int trackIndex, String animationName, bool loop) {
|
||||||
@ -245,34 +247,6 @@ namespace Spine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class EventTriggeredArgs : EventArgs {
|
|
||||||
public int TrackIndex { get; private set; }
|
|
||||||
public Event Event { get; private set; }
|
|
||||||
|
|
||||||
public EventTriggeredArgs (int trackIndex, Event e) {
|
|
||||||
TrackIndex = trackIndex;
|
|
||||||
Event = e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class CompleteArgs : EventArgs {
|
|
||||||
public int TrackIndex { get; private set; }
|
|
||||||
public int LoopCount { get; private set; }
|
|
||||||
|
|
||||||
public CompleteArgs (int trackIndex, int loopCount) {
|
|
||||||
TrackIndex = trackIndex;
|
|
||||||
LoopCount = loopCount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class StartEndArgs : EventArgs {
|
|
||||||
public int TrackIndex { get; private set; }
|
|
||||||
|
|
||||||
public StartEndArgs (int trackIndex) {
|
|
||||||
TrackIndex = trackIndex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class TrackEntry {
|
public class TrackEntry {
|
||||||
internal TrackEntry next, previous;
|
internal TrackEntry next, previous;
|
||||||
internal Animation animation;
|
internal Animation animation;
|
||||||
@ -287,26 +261,26 @@ namespace Spine {
|
|||||||
public float EndTime { get { return endTime; } set { endTime = value; } }
|
public float EndTime { get { return endTime; } set { endTime = value; } }
|
||||||
public float TimeScale { get { return timeScale; } set { timeScale = value; } }
|
public float TimeScale { get { return timeScale; } set { timeScale = value; } }
|
||||||
public bool Loop { get { return loop; } set { loop = value; } }
|
public bool Loop { get { return loop; } set { loop = value; } }
|
||||||
|
|
||||||
public event EventHandler<StartEndArgs> Start;
|
public AnimationState.StartEndDelegate Start;
|
||||||
public event EventHandler<StartEndArgs> End;
|
public AnimationState.StartEndDelegate End;
|
||||||
public event EventHandler<EventTriggeredArgs> Event;
|
public AnimationState.EventDelegate Event;
|
||||||
public event EventHandler<CompleteArgs> Complete;
|
public AnimationState.CompleteDelete Complete;
|
||||||
|
|
||||||
internal void OnStart (AnimationState state, int index) {
|
internal void OnStart (AnimationState state, int index) {
|
||||||
if (Start != null) Start(state, new StartEndArgs(index));
|
if (Start != null) Start(state, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void OnEnd (AnimationState state, int index) {
|
internal void OnEnd (AnimationState state, int index) {
|
||||||
if (End != null) End(state, new StartEndArgs(index));
|
if (End != null) End(state, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void OnEvent (AnimationState state, int index, Event e) {
|
internal void OnEvent (AnimationState state, int index, Event e) {
|
||||||
if (Event != null) Event(state, new EventTriggeredArgs(index, e));
|
if (Event != null) Event(state, index, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void OnComplete (AnimationState state, int index, int loopCount) {
|
internal void OnComplete (AnimationState state, int index, int loopCount) {
|
||||||
if (Complete != null) Complete(state, new CompleteArgs(index, loopCount));
|
if (Complete != null) Complete(state, index, loopCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
override public String ToString () {
|
override public String ToString () {
|
||||||
|
|||||||
@ -38,9 +38,9 @@ public class Spineboy : MonoBehaviour {
|
|||||||
skeleton = GetComponent<SkeletonAnimation>();
|
skeleton = GetComponent<SkeletonAnimation>();
|
||||||
skeleton.state.Event += Event;
|
skeleton.state.Event += Event;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Event (object sender, EventTriggeredArgs e) {
|
public void Event (Spine.AnimationState state, int trackIndex, Spine.Event e) {
|
||||||
Debug.Log(e.TrackIndex + " " + skeleton.state.GetCurrent(e.TrackIndex) + ": event " + e.Event + ", " + e.Event.Int);
|
Debug.Log(trackIndex + " " + state.GetCurrent(trackIndex) + ": event " + e + ", " + e.Int);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnMouseDown() {
|
void OnMouseDown() {
|
||||||
|
|||||||
@ -28,12 +28,25 @@
|
|||||||
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using Spine;
|
||||||
|
|
||||||
public class Goblins : MonoBehaviour {
|
public class Goblins : MonoBehaviour {
|
||||||
private bool girlSkin;
|
private bool girlSkin;
|
||||||
|
private SkeletonAnimation skeletonAnimation;
|
||||||
|
private Bone headBone;
|
||||||
|
|
||||||
|
public void Start () {
|
||||||
|
skeletonAnimation = GetComponent<SkeletonAnimation>();
|
||||||
|
headBone = skeletonAnimation.skeleton.FindBone("head");
|
||||||
|
skeletonAnimation.UpdateBones += UpdateBones;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is called after the animation is applied to the skeleton and can be used to adjust the bones dynamically.
|
||||||
|
public void UpdateBones (SkeletonComponent skeletonAnimation) {
|
||||||
|
headBone.Rotation -= 15;
|
||||||
|
}
|
||||||
|
|
||||||
public void OnMouseDown () {
|
public void OnMouseDown () {
|
||||||
SkeletonAnimation skeletonAnimation = GetComponent<SkeletonAnimation>();
|
|
||||||
skeletonAnimation.skeleton.SetSkin(girlSkin ? "goblin" : "goblingirl");
|
skeletonAnimation.skeleton.SetSkin(girlSkin ? "goblin" : "goblingirl");
|
||||||
skeletonAnimation.skeleton.SetSlotsToSetupPose();
|
skeletonAnimation.skeleton.SetSlotsToSetupPose();
|
||||||
|
|
||||||
|
|||||||
@ -39,8 +39,8 @@ public class Spineboy : MonoBehaviour {
|
|||||||
skeletonAnimation.state.Event += Event;
|
skeletonAnimation.state.Event += Event;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Event (object sender, EventTriggeredArgs e) {
|
public void Event (Spine.AnimationState state, int trackIndex, Spine.Event e) {
|
||||||
Debug.Log(e.TrackIndex + " " + skeletonAnimation.state.GetCurrent(e.TrackIndex) + ": event " + e.Event + ", " + e.Event.Int);
|
Debug.Log(trackIndex + " " + state.GetCurrent(trackIndex) + ": event " + e + ", " + e.Int);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnMouseDown () {
|
public void OnMouseDown () {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user