diff --git a/spine-csharp/src/AnimationState.cs b/spine-csharp/src/AnimationState.cs index d6693fbc7..713c2de72 100644 --- a/spine-csharp/src/AnimationState.cs +++ b/spine-csharp/src/AnimationState.cs @@ -40,13 +40,15 @@ namespace Spine { public AnimationStateData Data { get { return data; } } public float TimeScale { get { return timeScale; } set { timeScale = value; } } - /// The list of tracks that have animations, which may contain nulls. - public List Tracks { get { return tracks; } } + public delegate void StartEndDelegate(AnimationState state, int trackIndex); + public StartEndDelegate Start; + public StartEndDelegate End; - public event EventHandler Start; - public event EventHandler End; - public event EventHandler Event; - public event EventHandler Complete; + public delegate void EventDelegate(AnimationState state, int trackIndex, Event e); + public EventDelegate Event; + + public delegate void CompleteDelete(AnimationState state, int trackIndex, int loopCount); + public CompleteDelete Complete; public AnimationState (AnimationStateData data) { 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)) { int count = (int)(time / endTime); 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; @@ -118,7 +120,7 @@ namespace Spine { for (int ii = 0, nn = events.Count; ii < nn; ii++) { Event e = events[ii]; 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; @@ -137,7 +139,7 @@ namespace Spine { if (current == null) return; current.OnEnd(this, trackIndex); - if (End != null) End(this, new StartEndArgs(trackIndex)); + if (End != null) End(this, trackIndex); tracks[trackIndex] = null; } @@ -156,7 +158,7 @@ namespace Spine { current.previous = null; 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); if (entry.mixDuration > 0) { @@ -172,7 +174,7 @@ namespace Spine { tracks[index] = entry; 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) { @@ -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 { internal TrackEntry next, previous; internal Animation animation; @@ -287,26 +261,26 @@ namespace Spine { public float EndTime { get { return endTime; } set { endTime = value; } } public float TimeScale { get { return timeScale; } set { timeScale = value; } } public bool Loop { get { return loop; } set { loop = value; } } - - public event EventHandler Start; - public event EventHandler End; - public event EventHandler Event; - public event EventHandler Complete; + + public AnimationState.StartEndDelegate Start; + public AnimationState.StartEndDelegate End; + public AnimationState.EventDelegate Event; + public AnimationState.CompleteDelete Complete; 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) { - if (End != null) End(state, new StartEndArgs(index)); + if (End != null) End(state, index); } 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) { - if (Complete != null) Complete(state, new CompleteArgs(index, loopCount)); + if (Complete != null) Complete(state, index, loopCount); } override public String ToString () { diff --git a/spine-tk2d/Assets/examples/spineboy/Spineboy.cs b/spine-tk2d/Assets/examples/spineboy/Spineboy.cs index 947fb37c0..02d111180 100644 --- a/spine-tk2d/Assets/examples/spineboy/Spineboy.cs +++ b/spine-tk2d/Assets/examples/spineboy/Spineboy.cs @@ -38,9 +38,9 @@ public class Spineboy : MonoBehaviour { skeleton = GetComponent(); skeleton.state.Event += Event; } - - public void Event (object sender, EventTriggeredArgs e) { - Debug.Log(e.TrackIndex + " " + skeleton.state.GetCurrent(e.TrackIndex) + ": event " + e.Event + ", " + e.Event.Int); + + public void Event (Spine.AnimationState state, int trackIndex, Spine.Event e) { + Debug.Log(trackIndex + " " + state.GetCurrent(trackIndex) + ": event " + e + ", " + e.Int); } void OnMouseDown() { diff --git a/spine-unity/Assets/examples/goblins/Goblins.cs b/spine-unity/Assets/examples/goblins/Goblins.cs index ab5af0eca..240507b87 100644 --- a/spine-unity/Assets/examples/goblins/Goblins.cs +++ b/spine-unity/Assets/examples/goblins/Goblins.cs @@ -28,12 +28,25 @@ using UnityEngine; using System.Collections; +using Spine; public class Goblins : MonoBehaviour { private bool girlSkin; + private SkeletonAnimation skeletonAnimation; + private Bone headBone; + + public void Start () { + skeletonAnimation = GetComponent(); + 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 () { - SkeletonAnimation skeletonAnimation = GetComponent(); skeletonAnimation.skeleton.SetSkin(girlSkin ? "goblin" : "goblingirl"); skeletonAnimation.skeleton.SetSlotsToSetupPose(); diff --git a/spine-unity/Assets/examples/spineboy/Spineboy.cs b/spine-unity/Assets/examples/spineboy/Spineboy.cs index 61c600e74..e81b7e0a7 100644 --- a/spine-unity/Assets/examples/spineboy/Spineboy.cs +++ b/spine-unity/Assets/examples/spineboy/Spineboy.cs @@ -39,8 +39,8 @@ public class Spineboy : MonoBehaviour { skeletonAnimation.state.Event += Event; } - public void Event (object sender, EventTriggeredArgs e) { - Debug.Log(e.TrackIndex + " " + skeletonAnimation.state.GetCurrent(e.TrackIndex) + ": event " + e.Event + ", " + e.Event.Int); + public void Event (Spine.AnimationState state, int trackIndex, Spine.Event e) { + Debug.Log(trackIndex + " " + state.GetCurrent(trackIndex) + ": event " + e + ", " + e.Int); } public void OnMouseDown () {