Class SplineContainer
A component that holds a list of Spline objects.
Inherited Members
Namespace: UnityEngine.Splines
Assembly: Unity.Splines.dll
Syntax
[Icon("Packages/com.unity.splines/Editor/Resources/Icons/SplineComponent.png")]
[AddComponentMenu("Splines/Spline Container")]
[ExecuteAlways]
public sealed class SplineContainer : MonoBehaviour, ISplineContainer, ISerializationCallbackReceiver
Properties
this[int]
Gets or sets the Spline at index
.
Declaration
public Spline this[int index] { get; }
Parameters
Type | Name | Description |
---|---|---|
int | index | The zero-based index of the element to get or set. |
Property Value
Type | Description |
---|---|
Spline |
KnotLinkCollection
A collection of all linked knots. Linked knots can be on different splines. However, knots can only link to other knots within the same container. This collection is used to maintain the validity of the links when operations such as knot insertions or removals are performed on the splines.
Declaration
public KnotLinkCollection KnotLinkCollection { get; }
Property Value
Type | Description |
---|---|
KnotLinkCollection |
Spline
The main Spline attached to this component.
Declaration
public Spline Spline { get; set; }
Property Value
Type | Description |
---|---|
Spline |
Splines
The list of all splines attached to that container.
Declaration
public IReadOnlyList<Spline> Splines { get; set; }
Property Value
Type | Description |
---|---|
IReadOnlyList<Spline> |
Methods
CalculateLength()
Calculate the length of Spline in world space.
Declaration
public float CalculateLength()
Returns
Type | Description |
---|---|
float | The length of Spline in world space |
CalculateLength(int)
Calculates the length of Splines[splineIndex]
in world space.
Declaration
public float CalculateLength(int splineIndex)
Parameters
Type | Name | Description |
---|---|---|
int | splineIndex | The index of the spline to evaluate. |
Returns
Type | Description |
---|---|
float | The length of |
Evaluate(int, float, out float3, out float3, out float3)
Computes the interpolated position, direction and upDirection at ratio t for the spline at index splineIndex
. Calling this method to get the
3 vectors is faster than calling independently EvaluateSplinePosition, EvaluateSplineTangent and EvaluateSplineUpVector
for the same time t as it reduces some redundant computation.
Declaration
public bool Evaluate(int splineIndex, float t, out float3 position, out float3 tangent, out float3 upVector)
Parameters
Type | Name | Description |
---|---|---|
int | splineIndex | The index of the spline to evaluate. |
float | t | A value between 0 and 1 that represents the ratio along the curve. |
float3 | position | The output variable for the float3 position at t. |
float3 | tangent | The output variable for the float3 tangent at t. |
float3 | upVector | The output variable for the float3 up direction at t. |
Returns
Type | Description |
---|---|
bool | True if a valid set of output variables is computed and false otherwise. |
Evaluate(float, out float3, out float3, out float3)
Computes interpolated position, direction and upDirection at ratio t. Calling this method to get the 3 vectors is faster than calling independently EvaluateSplinePosition, EvaluateSplineTangent and EvaluateSplineUpVector for the same time t as it reduces some redundant computation.
Declaration
public bool Evaluate(float t, out float3 position, out float3 tangent, out float3 upVector)
Parameters
Type | Name | Description |
---|---|---|
float | t | A value between 0 and 1 representing the ratio along the curve. |
float3 | position | The output variable for the float3 position at t. |
float3 | tangent | The output variable for the float3 tangent at t. |
float3 | upVector | The output variable for the float3 up direction at t. |
Returns
Type | Description |
---|---|
bool | Boolean value, true if a valid set of output variables as been computed. |
EvaluateAcceleration(int, float)
Evaluates the acceleration vector of a point, t, on a spline at an index, `splineIndex, in world space.
Declaration
public float3 EvaluateAcceleration(int splineIndex, float t)
Parameters
Type | Name | Description |
---|---|---|
int | splineIndex | The index of the spline to evaluate. |
float | t | A value between 0 and 1 representing a percentage of entire spline. |
Returns
Type | Description |
---|---|
float3 | The computed acceleration vector. |
EvaluateAcceleration(float)
Evaluates the acceleration vector of a point, t, on a spline in world space.
Declaration
public float3 EvaluateAcceleration(float t)
Parameters
Type | Name | Description |
---|---|---|
float | t | A value between 0 and 1 representing a percentage of entire spline. |
Returns
Type | Description |
---|---|
float3 | The computed acceleration vector. |
EvaluateAcceleration<T>(T, float)
Evaluates the acceleration vector of a point, t, on a given Spline, in world space.
Declaration
public float3 EvaluateAcceleration<T>(T spline, float t) where T : ISpline
Parameters
Type | Name | Description |
---|---|---|
T | spline | The Spline to evaluate. |
float | t | A value between 0 and 1 representing a percentage of entire spline. |
Returns
Type | Description |
---|---|
float3 | The computed acceleration vector. |
Type Parameters
Name | Description |
---|---|
T | The spline type. |
EvaluatePosition(int, float)
Evaluates the position of a point, t, on a spline at an index, splineIndex
, in world space.
Declaration
public float3 EvaluatePosition(int splineIndex, float t)
Parameters
Type | Name | Description |
---|---|---|
int | splineIndex | The index of the spline to evaluate. |
float | t | A value between 0 and 1 representing a percentage of the curve. |
Returns
Type | Description |
---|---|
float3 | A world position along the spline. |
EvaluatePosition(float)
Evaluates the position of a point, t, on a spline in world space.
Declaration
public float3 EvaluatePosition(float t)
Parameters
Type | Name | Description |
---|---|---|
float | t | A value between 0 and 1 representing a percentage of the curve. |
Returns
Type | Description |
---|---|
float3 | A tangent vector. |
EvaluatePosition<T>(T, float)
Evaluates the position of a point, t, on a given spline, in world space.
Declaration
public float3 EvaluatePosition<T>(T spline, float t) where T : ISpline
Parameters
Type | Name | Description |
---|---|---|
T | spline | The spline to evaluate. |
float | t | A value between 0 and 1 representing a percentage of the curve. |
Returns
Type | Description |
---|---|
float3 | A world position along the spline. |
Type Parameters
Name | Description |
---|---|
T | The spline type. |
EvaluateTangent(int, float)
Evaluates the tangent vector of a point, t, on a spline at an index, splineIndex
, in world space.
Declaration
public float3 EvaluateTangent(int splineIndex, float t)
Parameters
Type | Name | Description |
---|---|---|
int | splineIndex | The index of the spline to evaluate. |
float | t | A value between 0 and 1 representing a percentage of entire spline. |
Returns
Type | Description |
---|---|
float3 | The computed tangent vector. |
EvaluateTangent(float)
Evaluates the tangent vector of a point, t, on a spline in world space.
Declaration
public float3 EvaluateTangent(float t)
Parameters
Type | Name | Description |
---|---|---|
float | t | A value between 0 and 1 representing a percentage of entire spline. |
Returns
Type | Description |
---|---|
float3 | The computed tangent vector. |
EvaluateTangent<T>(T, float)
Evaluates the tangent vector of a point, t, on a given spline, in world space.
Declaration
public float3 EvaluateTangent<T>(T spline, float t) where T : ISpline
Parameters
Type | Name | Description |
---|---|---|
T | spline | The spline to evaluate. |
float | t | A value between 0 and 1 representing a percentage of entire spline. |
Returns
Type | Description |
---|---|
float3 | The computed tangent vector. |
Type Parameters
Name | Description |
---|---|
T | The spline type. |
EvaluateUpVector(int, float)
Evaluates the up vector of a point, t, on a spline at an index, splineIndex
, in world space.
Declaration
public float3 EvaluateUpVector(int splineIndex, float t)
Parameters
Type | Name | Description |
---|---|---|
int | splineIndex | The index of the Spline to evaluate. |
float | t | A value between 0 and 1 representing a percentage of entire spline. |
Returns
Type | Description |
---|---|
float3 | The computed up direction. |
EvaluateUpVector(float)
Evaluates the up vector of a point, t, on a spline in world space.
Declaration
public float3 EvaluateUpVector(float t)
Parameters
Type | Name | Description |
---|---|---|
float | t | A value between 0 and 1 representing a percentage of entire spline. |
Returns
Type | Description |
---|---|
float3 | The computed up direction. |
EvaluateUpVector<T>(T, float)
Evaluates the up vector of a point, t, on a given spline, in world space.
Declaration
public float3 EvaluateUpVector<T>(T spline, float t) where T : ISpline
Parameters
Type | Name | Description |
---|---|---|
T | spline | The Spline to evaluate. |
float | t | A value between 0 and 1 representing a percentage of entire spline. |
Returns
Type | Description |
---|---|
float3 | The computed up direction. |
Type Parameters
Name | Description |
---|---|
T | The spline type. |
Evaluate<T>(T, float, out float3, out float3, out float3)
Gets the interpolated position, direction, and upDirection at ratio t for a spline. This method gets the three vectors faster than EvaluateSplinePosition, EvaluateSplineTangent and EvaluateSplineUpVector for the same time t, because it reduces some redundant computation.
Declaration
public bool Evaluate<T>(T spline, float t, out float3 position, out float3 tangent, out float3 upVector) where T : ISpline
Parameters
Type | Name | Description |
---|---|---|
T | spline | The spline to evaluate. |
float | t | A value between 0 and 1 that represents the ratio along the curve. |
float3 | position | The output variable for the float3 position at t. |
float3 | tangent | The output variable for the float3 tangent at t. |
float3 | upVector | The output variable for the float3 up direction at t. |
Returns
Type | Description |
---|---|
bool | True if a valid set of output variables is computed and false otherwise. |
Type Parameters
Name | Description |
---|---|
T | The spline type. |
OnAfterDeserialize()
See ISerializationCallbackReceiver.
Declaration
public void OnAfterDeserialize()
OnBeforeSerialize()
See ISerializationCallbackReceiver.
Declaration
public void OnBeforeSerialize()
Warmup()
Ensure that all caches contain valid data. Call this to avoid unexpected performance costs when evaluating splines data. Caches remain valid until any part of the splines state is modified.
Declaration
public void Warmup()
Events
SplineAdded
Invoked any time a spline is added to the container.
Declaration
public static event Action<SplineContainer, int> SplineAdded
Event Type
Type | Description |
---|---|
Action<SplineContainer, int> |
Remarks
The parameter corresponds to the spline index.
SplineRemoved
Invoked any time a spline is removed from the container.
Declaration
public static event Action<SplineContainer, int> SplineRemoved
Event Type
Type | Description |
---|---|
Action<SplineContainer, int> |
Remarks
The parameter corresponds to the spline index.
SplineReordered
Invoked any time a spline is reordered in the container.
Declaration
public static event Action<SplineContainer, int, int> SplineReordered
Event Type
Type | Description |
---|---|
Action<SplineContainer, int, int> |
Remarks
The first parameter corresponds to the previous spline index, the second parameter corresponds to the new spline index.