Class FixedCurveUnityExtensions
- Namespace
- FixedMathSharp
Provides explicit conversions between Unity animation curves and deterministic fixed curves.
public static class FixedCurveUnityExtensions
- Inheritance
-
FixedCurveUnityExtensions
- Inherited Members
Methods
BakeToFixedCurve(AnimationCurve, int)
Samples a Unity animation curve at inclusive, evenly spaced endpoints and converts the samples to a linear fixed curve.
public static FixedCurve BakeToFixedCurve(this AnimationCurve curve, int sampleCount)
Parameters
curveAnimationCurveThe Unity curve to sample at the authoring boundary.
sampleCountintThe number of samples, including both authored endpoints. Must be at least two.
Returns
- FixedCurve
A linear fixed curve approximating
curveat the requested samples.
Remarks
This is an explicit approximation for Unity authoring data and preserves neither tangents nor wrapping modes. Empty and one-key curves become constant fixed curves with zero and the authored key value respectively.
Exceptions
- ArgumentNullException
curveis null.- ArgumentOutOfRangeException
sampleCountis less than two, or a sampled time or value is not finite.- InvalidOperationException
The authored time span is not finite and positive, or the requested sample times are not distinct in the fixed-point domain.
- OverflowException
A sampled time or value is outside the representable fixed-point range.
ToAnimationCurve(FixedCurve)
Converts a fixed curve to a clamped, unweighted Unity animation curve.
public static AnimationCurve ToAnimationCurve(this FixedCurve curve)
Parameters
curveFixedCurveThe deterministic fixed curve to convert.
Returns
- AnimationCurve
A Unity curve with UnityEngine.WeightedMode.None keys and UnityEngine.WrapMode.ClampForever wrapping.
Remarks
Linear, step, smooth, and cubic modes map to Unity linear slopes, positive-infinity step tangents, zero tangents, and duration-scaled cubic tangents respectively. Endpoint-only tangents remain zero. An empty fixed curve maps to a clamped constant-one Unity curve.
Exceptions
- InvalidOperationException
The fixed curve has no storage, an unsupported mode, or keys/tangents that cannot remain finite and strictly ordered after conversion to Unity floats.
ToFixedCurve(AnimationCurve)
Converts a Unity animation curve to an exactly equivalent deterministic fixed curve.
public static FixedCurve ToFixedCurve(this AnimationCurve curve)
Parameters
curveAnimationCurveThe Unity curve to convert.
Returns
- FixedCurve
The exactly equivalent fixed curve.
Exceptions
- ArgumentNullException
curveis null.- InvalidOperationException
curvecannot be represented exactly; useBakeToFixedCurvefor an explicit sampled approximation.
TryToFixedCurve(AnimationCurve, out FixedCurve)
Attempts to convert a Unity animation curve to an exactly equivalent deterministic fixed curve.
public static bool TryToFixedCurve(this AnimationCurve curve, out FixedCurve fixedCurve)
Parameters
curveAnimationCurveThe Unity curve to convert. It must use UnityEngine.WrapMode.ClampForever before and after its keys.
fixedCurveFixedCurveThe exactly equivalent fixed curve on success; otherwise a zero-valued constant curve.
Returns
- bool
true when
curveis unweighted, uses one global step or Hermite interpolation mode, and has finite values, strictly increasing times, and duration-scaled tangents representable as Fixed64; otherwise, false.
Remarks
A successful conversion preserves clamped wrapping exactly and scales Hermite tangents by the adjacent segment duration. Curves with weighted keys, mixed step and Hermite segments, non-finite values, unrepresentable scaled tangents, or times that collapse or overflow in fixed-point representation fail safely without returning partial data.
Exceptions
- ArgumentNullException
curveis null.