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