remove string comparisons in SkeletonAnimator

This commit is contained in:
ZimM 2015-02-28 03:10:07 +02:00
parent ab396af5f3
commit de4fc8b483

View File

@ -62,8 +62,8 @@ public class SkeletonAnimator : SkeletonRenderer, ISkeletonAnimation {
protected event UpdateBonesDelegate _UpdateWorld; protected event UpdateBonesDelegate _UpdateWorld;
protected event UpdateBonesDelegate _UpdateComplete; protected event UpdateBonesDelegate _UpdateComplete;
Dictionary<string, Spine.Animation> animationTable = new Dictionary<string, Spine.Animation>(); Dictionary<int, Spine.Animation> animationTable = new Dictionary<int, Spine.Animation>();
Dictionary<AnimationClip, string> clipNameTable = new Dictionary<AnimationClip, string>(); Dictionary<AnimationClip, int> clipNameHashCodeTable = new Dictionary<AnimationClip, int>();
Animator animator; Animator animator;
public override void Reset () { public override void Reset () {
@ -72,12 +72,12 @@ public class SkeletonAnimator : SkeletonRenderer, ISkeletonAnimation {
return; return;
animationTable.Clear(); animationTable.Clear();
clipNameTable.Clear(); clipNameHashCodeTable.Clear();
var data = skeletonDataAsset.GetSkeletonData(true); var data = skeletonDataAsset.GetSkeletonData(true);
foreach (var a in data.Animations) { foreach (var a in data.Animations) {
animationTable.Add(a.Name, a); animationTable.Add(a.Name.GetHashCode(), a);
} }
animator = GetComponent<Animator>(); animator = GetComponent<Animator>();
@ -124,7 +124,7 @@ public class SkeletonAnimator : SkeletonRenderer, ISkeletonAnimation {
continue; continue;
float time = stateInfo.normalizedTime * info.clip.length; float time = stateInfo.normalizedTime * info.clip.length;
animationTable[GetAnimationClipName(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, null, weight);
} }
foreach (var info in nextClipInfo) { foreach (var info in nextClipInfo) {
@ -133,7 +133,7 @@ public class SkeletonAnimator : SkeletonRenderer, ISkeletonAnimation {
continue; continue;
float time = nextStateInfo.normalizedTime * info.clip.length; float time = nextStateInfo.normalizedTime * info.clip.length;
animationTable[GetAnimationClipName(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, null, weight);
} }
} else if (mode >= MixMode.MixNext) { } else if (mode >= MixMode.MixNext) {
//apply first non-zero weighted clip //apply first non-zero weighted clip
@ -146,7 +146,7 @@ public class SkeletonAnimator : SkeletonRenderer, ISkeletonAnimation {
continue; continue;
float time = stateInfo.normalizedTime * info.clip.length; float time = stateInfo.normalizedTime * info.clip.length;
animationTable[GetAnimationClipName(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, null);
break; break;
} }
@ -158,7 +158,7 @@ public class SkeletonAnimator : SkeletonRenderer, ISkeletonAnimation {
continue; continue;
float time = stateInfo.normalizedTime * info.clip.length; float time = stateInfo.normalizedTime * info.clip.length;
animationTable[GetAnimationClipName(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, null, weight);
} }
c = 0; c = 0;
@ -172,7 +172,7 @@ public class SkeletonAnimator : SkeletonRenderer, ISkeletonAnimation {
continue; continue;
float time = nextStateInfo.normalizedTime * info.clip.length; float time = nextStateInfo.normalizedTime * info.clip.length;
animationTable[GetAnimationClipName(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, null);
break; break;
} }
} }
@ -185,7 +185,7 @@ public class SkeletonAnimator : SkeletonRenderer, ISkeletonAnimation {
continue; continue;
float time = nextStateInfo.normalizedTime * info.clip.length; float time = nextStateInfo.normalizedTime * info.clip.length;
animationTable[GetAnimationClipName(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, null, weight);
} }
} }
} }
@ -205,13 +205,13 @@ public class SkeletonAnimator : SkeletonRenderer, ISkeletonAnimation {
} }
} }
private string GetAnimationClipName(AnimationClip clip) { private int GetAnimationClipNameHashCode(AnimationClip clip) {
string clipName; int clipNameHashCode;
if (!clipNameTable.TryGetValue(clip, out clipName)) { if (!clipNameHashCodeTable.TryGetValue(clip, out clipNameHashCode)) {
clipName = clip.name; clipNameHashCode = clip.name.GetHashCode();
clipNameTable.Add(clip, clipName); clipNameHashCodeTable.Add(clip, clipNameHashCode);
} }
return clipName; return clipNameHashCode;
} }
} }