[unity] Fixed exception at prefab baking. Closes #2034.

This commit is contained in:
Harald Csaszar 2022-02-16 19:51:02 +01:00
parent 5af852d83f
commit c523576895

View File

@ -809,20 +809,11 @@ namespace Spine.Unity.Editor {
return clip; return clip;
} }
static int BinarySearch (float[] values, float target) { internal static int Search (float[] frames, float time) {
int low = 0; int n = frames.Length;
int high = values.Length - 2; for (int i = 1; i < n; i++)
if (high == 0) return 1; if (frames[i] > time) return i - 1;
int current = (int)((uint)high >> 1); return n - 1;
while (true) {
if (values[(current + 1)] <= target)
low = current + 1;
else
high = current;
if (low == high) return (low + 1);
current = (int)((uint)(low + high) >> 1);
}
} }
static void BakeBoneConstraints (Bone bone, Spine.Animation animation, AnimationClip clip) { static void BakeBoneConstraints (Bone bone, Spine.Animation animation, AnimationClip clip) {
@ -978,8 +969,7 @@ namespace Spine.Unity.Editor {
lastTime = time; lastTime = time;
listIndex++; listIndex++;
} else if (curveType == 2) { } else {
//bezier //bezier
Keyframe px = xKeys[pIndex]; Keyframe px = xKeys[pIndex];
Keyframe py = yKeys[pIndex]; Keyframe py = yKeys[pIndex];
@ -1059,7 +1049,6 @@ namespace Spine.Unity.Editor {
while (currentTime < endTime) { while (currentTime < endTime) {
int pIndex = listIndex - 1; int pIndex = listIndex - 1;
float curveType = timeline.GetCurveType(frameIndex - 1); float curveType = timeline.GetCurveType(frameIndex - 1);
if (curveType == 0) { if (curveType == 0) {
//linear //linear
Keyframe px = xKeys[pIndex]; Keyframe px = xKeys[pIndex];
@ -1114,7 +1103,7 @@ namespace Spine.Unity.Editor {
lastTime = time; lastTime = time;
listIndex++; listIndex++;
} else if (curveType == 2) { } else {
//bezier //bezier
Keyframe px = xKeys[pIndex]; Keyframe px = xKeys[pIndex];
Keyframe py = yKeys[pIndex]; Keyframe py = yKeys[pIndex];
@ -1241,7 +1230,7 @@ namespace Spine.Unity.Editor {
lastTime = time; lastTime = time;
listIndex++; listIndex++;
} else if (curveType == 2) { } else {
//bezier //bezier
Keyframe pk = keys[pIndex]; Keyframe pk = keys[pIndex];
@ -1366,7 +1355,7 @@ namespace Spine.Unity.Editor {
while (currentTime < endTime) { while (currentTime < endTime) {
float time = frames[f]; float time = frames[f];
int frameIndex = (time >= frames[frames.Length - 1] ? frames.Length : BinarySearch(frames, time)) - 1; int frameIndex = Search(frames, time);
string name = timeline.AttachmentNames[frameIndex]; string name = timeline.AttachmentNames[frameIndex];
foreach (var pair in curveTable) { foreach (var pair in curveTable) {