[unity] SkeletonAnimator log errors.

This commit is contained in:
John 2017-06-10 02:27:24 +08:00 committed by GitHub
parent dd0f489eae
commit 0554c5bb97

View File

@ -145,14 +145,18 @@ namespace Spine.Unity {
// Always use Mix instead of Applying the first non-zero weighted clip. // Always use Mix instead of Applying the first non-zero weighted clip.
for (int c = 0; c < clipInfo.Length; c++) { for (int c = 0; c < clipInfo.Length; c++) {
var info = clipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) continue; var info = clipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) continue;
animationTable.TryGetValue(NameHashCode(info.clip), out spineAnimation); if (animationTable.TryGetValue(NameHashCode(info.clip), out spineAnimation))
if (spineAnimation != null) spineAnimation.Apply(skeleton, 0, AnimationTime(stateInfo.normalizedTime, info.clip.length, stateInfo.loop, stateInfo.speed <0), stateInfo.loop, null, weight, false, false); spineAnimation.Apply(skeleton, 0, AnimationTime(stateInfo.normalizedTime, info.clip.length, stateInfo.loop, stateInfo.speed < 0), stateInfo.loop, null, weight, false, false);
else if (logErrors)
SkeletonAnimator.LogMissingAnimationClip(this, info.clip.name);
} }
if (hasNext) { if (hasNext) {
for (int c = 0; c < nextClipInfo.Length; c++) { for (int c = 0; c < nextClipInfo.Length; c++) {
var info = nextClipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) continue; var info = nextClipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) continue;
animationTable.TryGetValue(NameHashCode(info.clip), out spineAnimation); if (animationTable.TryGetValue(NameHashCode(info.clip), out spineAnimation))
if (spineAnimation != null) spineAnimation.Apply(skeleton, 0, AnimationTime(nextStateInfo.normalizedTime , info.clip.length, nextStateInfo.speed < 0), nextStateInfo.loop, null, weight, false, false); spineAnimation.Apply(skeleton, 0, AnimationTime(nextStateInfo.normalizedTime, info.clip.length, nextStateInfo.speed < 0), nextStateInfo.loop, null, weight, false, false);
else if (logErrors)
SkeletonAnimator.LogMissingAnimationClip(this, info.clip.name);
} }
} }
} else { // case MixNext || SpineStyle } else { // case MixNext || SpineStyle
@ -160,15 +164,19 @@ namespace Spine.Unity {
int c = 0; int c = 0;
for (; c < clipInfo.Length; c++) { for (; c < clipInfo.Length; c++) {
var info = clipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) continue; var info = clipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) continue;
animationTable.TryGetValue(NameHashCode(info.clip), out spineAnimation); if (animationTable.TryGetValue(NameHashCode(info.clip), out spineAnimation))
if (spineAnimation != null) spineAnimation.Apply(skeleton, 0, AnimationTime(stateInfo.normalizedTime, info.clip.length, stateInfo.loop, stateInfo.speed <0), stateInfo.loop, null, 1f, false, false); spineAnimation.Apply(skeleton, 0, AnimationTime(stateInfo.normalizedTime, info.clip.length, stateInfo.loop, stateInfo.speed < 0), stateInfo.loop, null, 1f, false, false);
else if (logErrors)
SkeletonAnimator.LogMissingAnimationClip(this, info.clip.name);
break; break;
} }
// Mix the rest // Mix the rest
for (; c < clipInfo.Length; c++) { for (; c < clipInfo.Length; c++) {
var info = clipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) continue; var info = clipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) continue;
animationTable.TryGetValue(NameHashCode(info.clip), out spineAnimation); if (animationTable.TryGetValue(NameHashCode(info.clip), out spineAnimation))
if (spineAnimation != null) spineAnimation.Apply(skeleton, 0, AnimationTime(stateInfo.normalizedTime, info.clip.length, stateInfo.loop, stateInfo.speed <0), stateInfo.loop, null, weight, false, false); spineAnimation.Apply(skeleton, 0, AnimationTime(stateInfo.normalizedTime, info.clip.length, stateInfo.loop, stateInfo.speed < 0), stateInfo.loop, null, weight, false, false);
else if (logErrors)
SkeletonAnimator.LogMissingAnimationClip(this, info.clip.name);
} }
c = 0; c = 0;
@ -177,16 +185,20 @@ namespace Spine.Unity {
if (mode == MixMode.SpineStyle) { if (mode == MixMode.SpineStyle) {
for (; c < nextClipInfo.Length; c++) { for (; c < nextClipInfo.Length; c++) {
var info = nextClipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) continue; var info = nextClipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) continue;
animationTable.TryGetValue(NameHashCode(info.clip), out spineAnimation); if (animationTable.TryGetValue(NameHashCode(info.clip), out spineAnimation))
if (spineAnimation != null) spineAnimation.Apply(skeleton, 0, AnimationTime(nextStateInfo.normalizedTime , info.clip.length,nextStateInfo.speed < 0), nextStateInfo.loop, null, 1f, false, false); spineAnimation.Apply(skeleton, 0, AnimationTime(nextStateInfo.normalizedTime , info.clip.length, nextStateInfo.speed < 0), nextStateInfo.loop, null, 1f, false, false);
else if (logErrors)
SkeletonAnimator.LogMissingAnimationClip(this, info.clip.name);
break; break;
} }
} }
// Mix the rest // Mix the rest
for (; c < nextClipInfo.Length; c++) { for (; c < nextClipInfo.Length; c++) {
var info = nextClipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) continue; var info = nextClipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) continue;
animationTable.TryGetValue(NameHashCode(info.clip), out spineAnimation); if (animationTable.TryGetValue(NameHashCode(info.clip), out spineAnimation))
if (spineAnimation != null) spineAnimation.Apply(skeleton, 0, AnimationTime(nextStateInfo.normalizedTime , info.clip.length,nextStateInfo.speed < 0), nextStateInfo.loop, null, weight, false, false); spineAnimation.Apply(skeleton, 0, AnimationTime(nextStateInfo.normalizedTime , info.clip.length, nextStateInfo.speed < 0), nextStateInfo.loop, null, weight, false, false);
else if (logErrors)
SkeletonAnimator.LogMissingAnimationClip(this, info.clip.name);
} }
} }
} }
@ -209,6 +221,10 @@ namespace Spine.Unity {
} }
} }
static void LogMissingAnimationClip (UnityEngine.Object o, string clipName) {
Debug.LogError("SkeletonAnimator " + o + "tried to use an AnimationClip [" + clipName + "] which not included in the main animation table.");
}
static float AnimationTime (float normalizedTime, float clipLength, bool loop, bool reversed) { static float AnimationTime (float normalizedTime, float clipLength, bool loop, bool reversed) {
if (reversed) if (reversed)
normalizedTime = (1-normalizedTime + (int)normalizedTime) + (int)normalizedTime; normalizedTime = (1-normalizedTime + (int)normalizedTime) + (int)normalizedTime;