Struct NativeSpline
A readonly representation of Spline that is optimized for efficient access and queries. NativeSpline can be constructed with a Spline and Transform. If a transform is applied, all values will be relative to the transformed knot positions.
Namespace: UnityEngine.Splines
Syntax
public struct NativeSpline : ISpline, IReadOnlyList<BezierKnot>, IDisposable
Remarks
NativeSpline is compatible with the job system.
Constructors
NativeSpline(IReadOnlyList<BezierKnot>, Boolean, float4x4, Allocator)
Create a new NativeSpline from a set of BezierKnot.
Declaration
public NativeSpline(IReadOnlyList<BezierKnot> knots, bool closed, float4x4 transform, Allocator allocator = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IReadOnlyList<BezierKnot> | knots | A collection of sequential BezierKnot forming the spline path. |
| Boolean | closed | Whether the spline is open (has a start and end point) or closed (forms an unbroken loop). |
| float4x4 | transform | Apply a transformation matrix to the control Knots. |
| Allocator | allocator | The memory allocation method to use when reserving space for native arrays. |
NativeSpline(ISpline, Allocator)
Create a new NativeSpline from a set of BezierKnot.
Declaration
public NativeSpline(ISpline spline, Allocator allocator = null)
Parameters
| Type | Name | Description |
|---|---|---|
| ISpline | spline | The ISpline object to convert to a NativeSpline. |
| Allocator | allocator | The memory allocation method to use when reserving space for native arrays. |
NativeSpline(ISpline, float4x4, Allocator)
Create a new NativeSpline from a set of BezierKnot.
Declaration
public NativeSpline(ISpline spline, float4x4 transform, Allocator allocator = null)
Parameters
| Type | Name | Description |
|---|---|---|
| ISpline | spline | The ISpline object to convert to a NativeSpline. |
| float4x4 | transform | A transform matrix to be applied to the spline knots and tangents. |
| Allocator | allocator | The memory allocation method to use when reserving space for native arrays. |
Properties
Closed
Whether the spline is open (has a start and end point) or closed (forms an unbroken loop).
Declaration
public readonly bool Closed { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
Implements
Count
Return the number of knots.
Declaration
public readonly int Count { get; }
Property Value
| Type | Description |
|---|---|
| Int32 |
Item[Int32]
Get the knot at index.
Declaration
public readonly BezierKnot this[int index] { get; }
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | index | The zero-based index of the knot. |
Property Value
| Type | Description |
|---|---|
| BezierKnot |
Knots
A NativeArray of BezierKnot that form this Spline.
Declaration
public readonly NativeArray<BezierKnot> Knots { get; }
Property Value
| Type | Description |
|---|---|
| NativeArray<BezierKnot> | Returns a reference to the knots array. |
Methods
Dispose()
Release allocated resources.
Declaration
public void Dispose()
GetCurve(Int32)
Get a BezierCurve from a knot index.
Declaration
public BezierCurve GetCurve(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | index | The knot index that serves as the first control point for this curve. |
Returns
| Type | Description |
|---|---|
| BezierCurve | A BezierCurve formed by the knot at index and the next knot. |
Implements
GetCurveInterpolation(Int32, Single)
Return the normalized interpolation (t) corresponding to a distance on a BezierCurve.
Declaration
public float GetCurveInterpolation(int curveIndex, float curveDistance)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | curveIndex | The zero-based index of the curve. |
| Single | curveDistance | The curve-relative distance to convert to an interpolation ratio (also referred to as 't'). |
Returns
| Type | Description |
|---|---|
| Single | The normalized interpolation ratio associated to distance on the designated curve. |
Implements
GetCurveLength(Int32)
Get the length of a BezierCurve.
Declaration
public float GetCurveLength(int curveIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | curveIndex | The 0 based index of the curve to find length for. |
Returns
| Type | Description |
|---|---|
| Single | The length of the bezier curve at index. |
Implements
GetEnumerator()
Get an enumerator that iterates through the BezierKnot collection.
Declaration
public IEnumerator<BezierKnot> GetEnumerator()
Returns
| Type | Description |
|---|---|
| IEnumerator<BezierKnot> | An IEnumerator that is used to iterate the BezierKnot collection. |
GetLength()
Return the sum of all curve lengths, accounting for Closed state. Note that this value is affected by the transform used to create this NativeSpline.
Declaration
public float GetLength()
Returns
| Type | Description |
|---|---|
| Single | Returns the sum length of all curves composing this spline, accounting for closed state. |