Merge remote-tracking branch 'origin/master'

This commit is contained in:
NathanSweet 2016-05-20 01:54:01 +02:00
commit 419982695f

View File

@ -1,9 +1,9 @@
/***************************************************************************** /*****************************************************************************
* SkeletonAnimator created by Mitch Thompson * SkeletonAnimator created by Mitch Thompson
* Full irrevocable rights and permissions granted to Esoteric Software * Full irrevocable rights and permissions granted to Esoteric Software
*****************************************************************************/ *****************************************************************************/
//#define USE_SPINE_EVENTS // Uncomment this define to use C# events to handle Spine events. (Does not disable Unity AnimationClip Events)
using UnityEngine; using UnityEngine;
using System.Collections.Generic; using System.Collections.Generic;
@ -33,17 +33,21 @@ namespace Spine.Unity {
protected event UpdateBonesDelegate _UpdateWorld; protected event UpdateBonesDelegate _UpdateWorld;
protected event UpdateBonesDelegate _UpdateComplete; protected event UpdateBonesDelegate _UpdateComplete;
public Skeleton Skeleton { public Skeleton Skeleton { get { return this.skeleton; } }
get {
return this.skeleton;
}
}
readonly Dictionary<int, Spine.Animation> animationTable = new Dictionary<int, Spine.Animation>(); readonly Dictionary<int, Spine.Animation> animationTable = new Dictionary<int, Spine.Animation>();
readonly Dictionary<AnimationClip, int> clipNameHashCodeTable = new Dictionary<AnimationClip, int>(); readonly Dictionary<AnimationClip, int> clipNameHashCodeTable = new Dictionary<AnimationClip, int>();
Animator animator; Animator animator;
float lastTime; float lastTime;
#if USE_SPINE_EVENTS
public delegate void SkeletonAnimatorEventDelegate (Spine.Event firedEvent, float weight);
public event SkeletonAnimatorEventDelegate AnimationEvent;
public readonly ExposedList<Spine.Event> events = new ExposedList<Spine.Event>();
#else
public readonly ExposedList<Spine.Event> events = null;
#endif
public override void Initialize (bool overwrite) { public override void Initialize (bool overwrite) {
if (valid && !overwrite) if (valid && !overwrite)
return; return;
@ -108,7 +112,10 @@ namespace Spine.Unity {
continue; continue;
float time = stateInfo.normalizedTime * info.clip.length; float time = stateInfo.normalizedTime * info.clip.length;
animationTable[GetAnimationClipNameHashCode(info.clip)].Mix(skeleton, Mathf.Max(0, time - deltaTime), time, stateInfo.loop, null, weight); animationTable[GetAnimationClipNameHashCode(info.clip)].Mix(skeleton, Mathf.Max(0, time - deltaTime), time, stateInfo.loop, events, weight);
#if USE_SPINE_EVENTS
FireEvents(events, weight, this.AnimationEvent);
#endif
} }
#if UNITY_5 #if UNITY_5
if (nextStateInfo.fullPathHash != 0) { if (nextStateInfo.fullPathHash != 0) {
@ -122,7 +129,10 @@ namespace Spine.Unity {
continue; continue;
float time = nextStateInfo.normalizedTime * info.clip.length; float time = nextStateInfo.normalizedTime * info.clip.length;
animationTable[GetAnimationClipNameHashCode(info.clip)].Mix(skeleton, Mathf.Max(0, time - deltaTime), time, nextStateInfo.loop, null, weight); animationTable[GetAnimationClipNameHashCode(info.clip)].Mix(skeleton, Mathf.Max(0, time - deltaTime), time, nextStateInfo.loop, events, weight);
#if USE_SPINE_EVENTS
FireEvents(events, weight, this.AnimationEvent);
#endif
} }
} }
} else if (mode >= MixMode.MixNext) { } else if (mode >= MixMode.MixNext) {
@ -136,7 +146,10 @@ namespace Spine.Unity {
continue; continue;
float time = stateInfo.normalizedTime * info.clip.length; float time = stateInfo.normalizedTime * info.clip.length;
animationTable[GetAnimationClipNameHashCode(info.clip)].Apply(skeleton, Mathf.Max(0, time - deltaTime), time, stateInfo.loop, null); animationTable[GetAnimationClipNameHashCode(info.clip)].Apply(skeleton, Mathf.Max(0, time - deltaTime), time, stateInfo.loop, events);
#if USE_SPINE_EVENTS
FireEvents(events, weight, this.AnimationEvent);
#endif
break; break;
} }
@ -148,7 +161,10 @@ namespace Spine.Unity {
continue; continue;
float time = stateInfo.normalizedTime * info.clip.length; float time = stateInfo.normalizedTime * info.clip.length;
animationTable[GetAnimationClipNameHashCode(info.clip)].Mix(skeleton, Mathf.Max(0, time - deltaTime), time, stateInfo.loop, null, weight); animationTable[GetAnimationClipNameHashCode(info.clip)].Mix(skeleton, Mathf.Max(0, time - deltaTime), time, stateInfo.loop, events, weight);
#if USE_SPINE_EVENTS
FireEvents(events, weight, this.AnimationEvent);
#endif
} }
c = 0; c = 0;
@ -166,7 +182,10 @@ namespace Spine.Unity {
continue; continue;
float time = nextStateInfo.normalizedTime * info.clip.length; float time = nextStateInfo.normalizedTime * info.clip.length;
animationTable[GetAnimationClipNameHashCode(info.clip)].Apply(skeleton, Mathf.Max(0, time - deltaTime), time, nextStateInfo.loop, null); animationTable[GetAnimationClipNameHashCode(info.clip)].Apply(skeleton, Mathf.Max(0, time - deltaTime), time, nextStateInfo.loop, events);
#if USE_SPINE_EVENTS
FireEvents(events, weight, this.AnimationEvent);
#endif
break; break;
} }
} }
@ -179,7 +198,10 @@ namespace Spine.Unity {
continue; continue;
float time = nextStateInfo.normalizedTime * info.clip.length; float time = nextStateInfo.normalizedTime * info.clip.length;
animationTable[GetAnimationClipNameHashCode(info.clip)].Mix(skeleton, Mathf.Max(0, time - deltaTime), time, nextStateInfo.loop, null, weight); animationTable[GetAnimationClipNameHashCode(info.clip)].Mix(skeleton, Mathf.Max(0, time - deltaTime), time, nextStateInfo.loop, events, weight);
#if USE_SPINE_EVENTS
FireEvents(events, weight, this.AnimationEvent);
#endif
} }
} }
} }
@ -211,5 +233,20 @@ namespace Spine.Unity {
return clipNameHashCode; return clipNameHashCode;
} }
#if USE_SPINE_EVENTS
static void FireEvents (ExposedList<Spine.Event> eventList, float weight, SkeletonAnimatorEventDelegate callback) {
int eventsCount = eventList.Count;
if (eventsCount > 0) {
var eventListItems = eventList.Items;
for (int i = 0; i < eventsCount; i++) {
if (callback != null)
callback(eventListItems[i], weight);
}
eventList.Clear(false);
}
}
#endif
} }
} }