Hi,
The four Bezier values should be transferrable to Unity's representation following this documentation as guidance:
Documentation page for Bone Timelines
, sub-section "Common bone keyframe attributes"
Spine: JSON export format: Bone timelines
"A Bézier curve has 4 elements which define the control points: cx1, cy1, cx2, cy2. The X axis is from 0 to 1 and represents the percent of time between the two keyframes. The Y axis is from 0 to 1 and represents the percent of the difference between the keyframe's values."
Note that the keyframes in Unity are described as: in_tangent_P_i left, out_tangent_P_i right of a control point with
ks[0].inTangent = 5f; // -5 units on the y axis for 1 unit on the x axis.
ks[0].outTangent = 5f; // +5 units on the y axis for 1 unit on the x axis.
https://docs.unity3d.com/ScriptReference/Keyframe-inTangent.html
https://docs.unity3d.com/ScriptReference/Keyframe-outTangent.html
In Spine it's [0-1] normalized x/y values of both tangent-control-points before P_i: points_for_out_tangent_P_i-1, points_for_in_tangent_P_i. Each tangent could then be described as: (y/x) * (y_value_diff/x_time_diff).
In short: it's absolute vs relative encoding here, and the out-tangent is stored at frame i in Unity and at frame i+1 in Spine.
One thing to consider, since you want to do this via an external script:
You could also consider modifying/replacing the SkeletonBaker
code parts that write the Unity anim Keyframes out.
I would perform the changes myself and extend the Skeleton Baker functionality by a "Only Keyframes" mode, but unfortunately we are currently very busy with major changes in the 3.8-beta branch (format changes, examples overhaul and a soon planned release). So I can currently only offer you help in descriptive form instead of implementing it, sorry for that.
What would be necessary to be changed/extended are the following code parts:
SkeletonBaker.cs: line 1245 - 1283
spine-runtimes/SkeletonBaker.cs at 3.7
static void ParseRotateTimeline (Skeleton skeleton, RotateTimeline timeline, AnimationClip clip)
[part where Bezier curve is evaluated]
Here the fixed baking increment of 1/60 seconds is used, you could instead use the values of the frame entries. Note that these are not four values, but only 2 per control point (due to consistent in-out tangents at each control point, pointing in opposite direction).
CurveTimeline class, SetCurve demonstrates how these values 4 parameter values are transformed to the frame entry:
Animation.cs: line 250-274
spine-runtimes/Animation.cs at 3.7
/// <summary>Sets the specified key frame to Bezier interpolation. <code>cx1</code> and <code>cx2</code> are from 0 to 1,
/// representing the percent of time between the two key frames. <code>cy1</code> and <code>cy2</code> are the percent of the
/// difference between the key frame's values.</summary>
public void SetCurve (int frameIndex, float cx1, float cy1, float cx2, float cy2)
I hope this helps.