[csharp][unity] Cleanup refactoring of TranslateTimeline.Evaluate code, see previous commit 91f7969c. See #1676.

This commit is contained in:
Harald Csaszar 2021-09-15 16:30:43 +02:00
parent f4021177f9
commit cd8064774f
2 changed files with 12 additions and 25 deletions

View File

@ -546,7 +546,7 @@ namespace Spine {
}
float x, y;
EvaluateCurve(out x, out y, time); // note: reference implementation has code inlined
GetCurveValue(out x, out y, time); // note: reference implementation has code inlined
switch (blend) {
case MixBlend.Setup:
@ -565,7 +565,7 @@ namespace Spine {
}
}
protected void EvaluateCurve (out float x, out float y, float time) {
public void GetCurveValue (out float x, out float y, float time) {
int i = Search(frames, time, ENTRIES), curveType = (int)curves[i / ENTRIES];
switch (curveType) {
case LINEAR:
@ -586,27 +586,6 @@ namespace Spine {
break;
}
}
/// <summary>Evaluates the resulting value of a TranslateTimeline at a given time.
/// If no SkeletonData is given, values are returned as difference to setup pose
/// instead of absolute values.</summary>
public void Evaluate (out float outX, out float outY, float time, SkeletonData skeletonData) {
outX = outY = 0;
if (time < frames[0]) return;
float x, y;
EvaluateCurve(out x, out y, time);
if (skeletonData == null) {
outX = x;
outY = y;
return;
} else {
var boneData = skeletonData.bones.Items[boneIndex];
outX = x + boneData.x;
outY = y + boneData.y;
}
}
}
/// <summary>Changes a bone's local <see cref"Bone.X"/>.</summary>

View File

@ -39,9 +39,17 @@ namespace Spine.Unity.AnimationTools {
/// If no SkeletonData is given, values are returned as difference to setup pose
/// instead of absolute values.</summary>
public static Vector2 Evaluate (this TranslateTimeline timeline, float time, SkeletonData skeletonData = null) {
if (time < timeline.Frames[0]) return Vector2.zero;
float x, y;
timeline.Evaluate(out x, out y, time, skeletonData);
return new Vector2(x, y);
timeline.GetCurveValue(out x, out y, time);
if (skeletonData == null) {
return new Vector2(x, y);
} else {
BoneData boneData = skeletonData.Bones.Items[timeline.BoneIndex];
return new Vector2(boneData.X + x, boneData.Y + y);
}
}
/// <summary>Gets the translate timeline for a given boneIndex.