From de4fc8b483a5fcc149f4659f87cdb11d6f8e3726 Mon Sep 17 00:00:00 2001 From: ZimM Date: Sat, 28 Feb 2015 03:10:07 +0200 Subject: [PATCH] remove string comparisons in SkeletonAnimator --- .../Assets/spine-unity/SkeletonAnimator.cs | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/spine-unity/Assets/spine-unity/SkeletonAnimator.cs b/spine-unity/Assets/spine-unity/SkeletonAnimator.cs index cf147ee7c..3eac9332d 100644 --- a/spine-unity/Assets/spine-unity/SkeletonAnimator.cs +++ b/spine-unity/Assets/spine-unity/SkeletonAnimator.cs @@ -62,8 +62,8 @@ public class SkeletonAnimator : SkeletonRenderer, ISkeletonAnimation { protected event UpdateBonesDelegate _UpdateWorld; protected event UpdateBonesDelegate _UpdateComplete; - Dictionary animationTable = new Dictionary(); - Dictionary clipNameTable = new Dictionary(); + Dictionary animationTable = new Dictionary(); + Dictionary clipNameHashCodeTable = new Dictionary(); Animator animator; public override void Reset () { @@ -72,12 +72,12 @@ public class SkeletonAnimator : SkeletonRenderer, ISkeletonAnimation { return; animationTable.Clear(); - clipNameTable.Clear(); + clipNameHashCodeTable.Clear(); var data = skeletonDataAsset.GetSkeletonData(true); foreach (var a in data.Animations) { - animationTable.Add(a.Name, a); + animationTable.Add(a.Name.GetHashCode(), a); } animator = GetComponent(); @@ -124,7 +124,7 @@ public class SkeletonAnimator : SkeletonRenderer, ISkeletonAnimation { continue; 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) { @@ -133,7 +133,7 @@ public class SkeletonAnimator : SkeletonRenderer, ISkeletonAnimation { continue; 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) { //apply first non-zero weighted clip @@ -146,7 +146,7 @@ public class SkeletonAnimator : SkeletonRenderer, ISkeletonAnimation { continue; 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; } @@ -158,7 +158,7 @@ public class SkeletonAnimator : SkeletonRenderer, ISkeletonAnimation { continue; 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; @@ -172,7 +172,7 @@ public class SkeletonAnimator : SkeletonRenderer, ISkeletonAnimation { continue; 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; } } @@ -185,7 +185,7 @@ public class SkeletonAnimator : SkeletonRenderer, ISkeletonAnimation { continue; 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) { - string clipName; - if (!clipNameTable.TryGetValue(clip, out clipName)) { - clipName = clip.name; - clipNameTable.Add(clip, clipName); + private int GetAnimationClipNameHashCode(AnimationClip clip) { + int clipNameHashCode; + if (!clipNameHashCodeTable.TryGetValue(clip, out clipNameHashCode)) { + clipNameHashCode = clip.name.GetHashCode(); + clipNameHashCodeTable.Add(clip, clipNameHashCode); } - return clipName; + return clipNameHashCode; } }