From cd8064774f897b0015e928c85d6c7044381ac8ca Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Wed, 15 Sep 2021 16:30:43 +0200 Subject: [PATCH] [csharp][unity] Cleanup refactoring of TranslateTimeline.Evaluate code, see previous commit 91f7969c. See #1676. --- spine-csharp/src/Animation.cs | 25 ++----------------- .../spine-unity/Utility/TimelineExtensions.cs | 12 +++++++-- 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/spine-csharp/src/Animation.cs b/spine-csharp/src/Animation.cs index d4611a454..c4dc2c5cf 100644 --- a/spine-csharp/src/Animation.cs +++ b/spine-csharp/src/Animation.cs @@ -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; } } - - /// 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. - 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; - } - } } /// Changes a bone's local . diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/TimelineExtensions.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/TimelineExtensions.cs index 20197bafa..9d9b60093 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/TimelineExtensions.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/TimelineExtensions.cs @@ -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. 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); + } } /// Gets the translate timeline for a given boneIndex.