Struct SplineSlice<T>
SplineSlice represents a partial or complete range of curves from another Spline. A SplineSlice<T> by itself does not store any BezierKnots. It stores a reference to a separate Spline, then retrieves knots by iterating the SplineRange. Use SplineSlice<T> in conjunction with SplinePath to create seamless paths from discrete Spline segments.
This class is a data structure that defines the range of curves to associate together. This class is not meant to be used intensively for runtime evaluation because it is not performant. Data is not meant to be stored in that struct and that struct is not reactive to spline changes. The GameObject that contains this slice can be scaled and the knots of the targeted spline that can moved around the curve length cannot be stored here so evaluating positions, tangents and up vectors is expensive.
If performance is a critical requirement, create a new Spline or NativeSpline from the relevant SplinePath<T> or SplineSlice<T>. Note that you might pass a SplineSlice<T> to constructors for both Spline and NativeSpline.
Implements
Inherited Members
Namespace: UnityEngine.Splines
Assembly: Unity.Splines.dll
Syntax
public struct SplineSlice<T> : ISpline, IReadOnlyList<BezierKnot>, IReadOnlyCollection<BezierKnot>, IEnumerable<BezierKnot>, IEnumerable where T : ISpline
Type Parameters
Name | Description |
---|---|
T | The type of spline that this slice represents. |
Remarks
Iterating a SplineSlice<T> is not as efficient as iterating a Spline or NativeSpline because it does not cache any information. Where performance is a concern, create a new Spline or NativeSpline from the SplineSlice<T>.
Constructors
SplineSlice(T, SplineRange)
Constructor for a new SplineSlice.
Declaration
public SplineSlice(T spline, SplineRange range)
Parameters
Type | Name | Description |
---|---|---|
T | spline | The Spline that this Slice will read BezierKnot and BezierCurve data from. |
SplineRange | range | The start index and count of knot indices that compose this slice. |
SplineSlice(T, SplineRange, float4x4)
Constructor for a new SplineSlice.
Declaration
public SplineSlice(T spline, SplineRange range, float4x4 transform)
Parameters
Type | Name | Description |
---|---|---|
T | spline | The Spline that this Slice will read BezierKnot and BezierCurve data from. |
SplineRange | range | The start index and count of knot indices that compose this slice. |
float4x4 | transform | A transform matrix to be applied to the spline knots and tangents. |
Fields
Range
An inclusive start index, number of indices, and direction to iterate.
Declaration
public SplineRange Range
Field Value
Type | Description |
---|---|
SplineRange |
Spline
The Spline that this Slice will read BezierKnot and BezierCurve data from. A SplineSlice<T> by itself does not store any BezierKnots. Instead, it references a partial or complete range of existing Splines.
Declaration
public T Spline
Field Value
Type | Description |
---|---|
T |
Transform
A transform matrix to be applied to the spline knots and tangents.
Declaration
public float4x4 Transform
Field Value
Type | Description |
---|---|
float4x4 |
Properties
Closed
Whether the spline is open (has a start and end point) or closed (forms an unbroken loop).
Declaration
public bool Closed { get; }
Property Value
Type | Description |
---|---|
bool |
Count
Return the number of knots in this branch. This function clamps the Range to the Count of the the referenced Spline.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
int |
this[int]
Get a BezierKnot at the zero-based index of this SplineSlice<T>.
Declaration
public BezierKnot this[int index] { get; }
Parameters
Type | Name | Description |
---|---|---|
int | index | The index to get. |
Property Value
Type | Description |
---|---|
BezierKnot |
Methods
GetCurve(int)
Get a BezierCurve from a knot index.
Declaration
public BezierCurve GetCurve(int index)
Parameters
Type | Name | Description |
---|---|---|
int | 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. |
GetCurveInterpolation(int, float)
Return the normalized interpolation (t) corresponding to a distance on a BezierCurve.
Declaration
public float GetCurveInterpolation(int curveIndex, float curveDistance)
Parameters
Type | Name | Description |
---|---|---|
int | curveIndex | The zero-based index of the curve. |
float | curveDistance | The curve-relative distance to convert to an interpolation ratio (also referred to as 't'). |
Returns
Type | Description |
---|---|
float | The normalized interpolation ratio associated to distance on the designated curve. |
Remarks
It is inefficient to call this method frequently, as it will calculate the interpolation lookup table every time it is invoked. In cases where performance is critical, create a new Spline or NativeSpline instead. Note that you may pass a SplineSlice<T> to constructors for both Spline and NativeSpline.
GetCurveLength(int)
Return the length of a curve.
Declaration
public float GetCurveLength(int index)
Parameters
Type | Name | Description |
---|---|---|
int | index | The index of the curve for which the length needs to be retrieved. |
Returns
Type | Description |
---|---|
float | Returns the length of the curve of index 'index' in the spline. |
Remarks
The curve length cannot be cached here because the transform matrix associated to this slice might impact that value, like using a non-uniform scale on the GameObject associated with that slice. It is inefficient to call this method frequently, because it calculates the length of the curve every time it is invoked. If performance is a critical requirement, create a new Spline or NativeSpline from the relevant SplinePath<T> or SplineSlice<T>. Note that you might pass a SplineSlice<T> to constructors for both Spline and NativeSpline.
See Also
GetCurveUpVector(int, float)
Return the up vector for a t ratio on the curve.
Declaration
public float3 GetCurveUpVector(int index, float t)
Parameters
Type | Name | Description |
---|---|---|
int | index | The index of the curve for which the length needs to be retrieved. |
float | t | A value between 0 and 1 representing the ratio along the curve. |
Returns
Type | Description |
---|---|
float3 | Returns the up vector at the t ratio of the curve of index 'index'. |
Remarks
It is inefficient to call this method frequently, as it will calculate the up Vector of the curve every time it is invoked. In cases where performance is critical, create a new Spline or NativeSpline instead. Note that you may pass a SplineSlice<T> to constructors for both Spline and NativeSpline.
GetEnumerator()
Get an enumerator that iterates through the BezierKnot collection. Note that this will either increment or decrement indices depending on the value of the Direction.
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.
Declaration
public float GetLength()
Returns
Type | Description |
---|---|
float | Returns the sum length of all curves composing this spline. |
Remarks
It is inefficient to call this method frequently, as it will calculate the length of all curves every time it is invoked. In cases where performance is critical, create a new Spline or NativeSpline instead. Note that you may pass a SplineSlice<T> to constructors for both Spline and NativeSpline.