Class Spline
The Spline class is a collection of BezierKnot, the closed/open state, and editing representation.
Implements
Inherited Members
Namespace: UnityEngine.Splines
Assembly: Unity.Splines.dll
Syntax
[Serializable]
public class Spline : ISpline, IReadOnlyList<BezierKnot>, IReadOnlyCollection<BezierKnot>, IList<BezierKnot>, ICollection<BezierKnot>, IEnumerable<BezierKnot>, IEnumerable
Constructors
Spline()
Default constructor creates a spline with no knots, not closed.
Declaration
public Spline()
Spline(IEnumerable<float3>, TangentMode, bool)
Create a spline from a collection of Unity.Mathematics.float3 knot positions. The knot positions are converted to BezierKnot. When the tangent mode is set to Mirrored, Continuous, Broken, or Linear, the final tangent values are obtained from tangents initially computed using Autosmooth to ensure accuracy.
Declaration
public Spline(IEnumerable<float3> knotPositions, TangentMode tangentMode = TangentMode.AutoSmooth, bool closed = false)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<float3> | knotPositions | The range of knot positions to add to the spline. |
TangentMode | tangentMode | The TangentMode to apply to this range of knot positions. The default value is Autosmooth. |
bool | closed | Whether the spline is open or closed. Open splines have a start and end point and closed splines form an unbroken loop. |
Spline(IEnumerable<BezierKnot>, bool)
Create a spline from a collection of BezierKnot.
Declaration
public Spline(IEnumerable<BezierKnot> knots, bool closed = false)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<BezierKnot> | knots | A collection of BezierKnot. |
bool | closed | Whether the spline is open (has a start and end point) or closed (forms an unbroken loop). |
Spline(int, bool)
Create a spline with a pre-allocated knot capacity.
Declaration
public Spline(int knotCapacity, bool closed = false)
Parameters
Type | Name | Description |
---|---|---|
int | knotCapacity | The capacity of the knot collection. |
bool | closed | Whether the spline is open (has a start and end point) or closed (forms an unbroken loop). |
Spline(Spline)
Create a copy of a spline.
Declaration
public Spline(Spline spline)
Parameters
Type | Name | Description |
---|---|---|
Spline | spline | The spline to copy in that new instance. |
Properties
Closed
Whether the spline is open (has a start and end point) or closed (forms an unbroken loop).
Declaration
public bool Closed { get; set; }
Property Value
Type | Description |
---|---|
bool |
Count
Return the number of knots.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
int |
IsReadOnly
Returns true if this Spline is read-only, false if it is mutable.
Declaration
public bool IsReadOnly { get; }
Property Value
Type | Description |
---|---|
bool |
this[int]
Get or set the knot at index
.
Declaration
public BezierKnot this[int index] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
int | index | The zero-based index of the element to get or set. |
Property Value
Type | Description |
---|---|
BezierKnot |
Knots
A collection of BezierKnot.
Declaration
public IEnumerable<BezierKnot> Knots { get; set; }
Property Value
Type | Description |
---|---|
IEnumerable<BezierKnot> |
Methods
Add(float3, TangentMode)
Creates a BezierKnot from a Unity.Mathematics.float3 knot position and adds it to the spline. When the tangent mode is set to Mirrored, Continuous, Broken, or Linear, the final tangent values are obtained from tangents initially computed using Autosmooth to ensure accuracy.
Declaration
public void Add(float3 knotPosition, TangentMode tangentMode = TangentMode.AutoSmooth)
Parameters
Type | Name | Description |
---|---|---|
float3 | knotPosition | The knot position to convert to a BezierKnot and add to the spline. |
TangentMode | tangentMode | The TangentMode to apply to the new element. The default value is Autosmooth. |
Add(BezierKnot)
Adds a knot to the spline.
Declaration
public void Add(BezierKnot item)
Parameters
Type | Name | Description |
---|---|---|
BezierKnot | item | The BezierKnot to add. |
Add(BezierKnot, TangentMode)
Adds a knot to the spline.
Declaration
public void Add(BezierKnot item, TangentMode mode)
Parameters
Type | Name | Description |
---|---|---|
BezierKnot | item | The BezierKnot to add. |
TangentMode | mode | The tangent mode for this knot. |
Add(BezierKnot, TangentMode, float)
Adds a knot to the spline.
Declaration
public void Add(BezierKnot item, TangentMode mode, float tension)
Parameters
Type | Name | Description |
---|---|---|
BezierKnot | item | The BezierKnot to add. |
TangentMode | mode | The tangent mode for this knot. |
float | tension | The modifier value that is used to calculate the magnitude of tangents when the TangentMode is AutoSmooth. Valid values are between 0 and 1. A lower value results in sharper curves, whereas higher values appear more rounded. |
Add(Spline)
Declaration
public void Add(Spline spline)
Parameters
Type | Name | Description |
---|---|---|
Spline | spline |
AddRange(IEnumerable<float3>, TangentMode)
Creates BezierKnot from a range of Unity.Mathematics.float3 knot positions and adds them to the spline. When the tangent mode is set to Mirrored, Continuous, Broken, or Linear, the final tangent values are obtained from tangents initially computed using Autosmooth to ensure accuracy.
Declaration
public void AddRange(IEnumerable<float3> knotPositions, TangentMode tangentMode = TangentMode.AutoSmooth)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<float3> | knotPositions | The range of knot positions to add to the spline. |
TangentMode | tangentMode | The TangentMode to apply to this range of knot positions. The default value is Autosmooth. |
Clear()
Remove all knots from the spline.
Declaration
public void Clear()
Contains(BezierKnot)
Return true if a knot is present in the spline.
Declaration
public bool Contains(BezierKnot item)
Parameters
Type | Name | Description |
---|---|---|
BezierKnot | item | The BezierKnot to locate. |
Returns
Type | Description |
---|---|
bool | Returns true if the knot is found, false if it is not present. |
Copy(Spline)
Copy the values from copyFrom
to this spline.
Declaration
public void Copy(Spline copyFrom)
Parameters
Type | Name | Description |
---|---|---|
Spline | copyFrom | The spline to copy property data from. |
CopyTo(BezierKnot[], int)
Copies the contents of the knot list to an array starting at an index.
Declaration
public void CopyTo(BezierKnot[] array, int arrayIndex)
Parameters
Type | Name | Description |
---|---|---|
BezierKnot[] | array | The destination array to place the copied item in. |
int | arrayIndex | The zero-based index to copy. |
EnforceTangentModeNoNotify(int)
Ensure that a BezierKnot has the correct tangent and rotation values to match it's TangentMode and tension. This can be necessary if knot data is modified outside of the Spline class (ex, manually setting the Knots array without taking care to also set the tangent modes).
Declaration
public void EnforceTangentModeNoNotify(int index)
Parameters
Type | Name | Description |
---|---|---|
int | index | The knot index to set tangent and rotation values for. |
EnforceTangentModeNoNotify(SplineRange)
Ensure that a BezierKnot has the correct tangent and rotation values to match it's TangentMode and tension. This can be necessary if knot data is modified outside of the Spline class (ex, manually setting the Knots array without taking care to also set the tangent modes).
Declaration
public void EnforceTangentModeNoNotify(SplineRange range)
Parameters
Type | Name | Description |
---|---|---|
SplineRange | range | The SplineRange range of knot indices to set tangent and rotation values for. |
GetAutoSmoothTension(int)
Gets the tension value for the requested index.
Declaration
public float GetAutoSmoothTension(int index)
Parameters
Type | Name | Description |
---|---|---|
int | index | The knot index to get a tension value for. |
Returns
Type | Description |
---|---|
float | Returns the tension value for the requested index. |
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. |
GetCurveLength(int)
Return the length of a curve.
Declaration
public float GetCurveLength(int index)
Parameters
Type | Name | Description |
---|---|---|
int | index |
Returns
Type | Description |
---|---|
float |
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'. |
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. |
GetFloat4DataKeys()
Get a collection of the keys of embedded SplineData<T> for this type.
Declaration
public IEnumerable<string> GetFloat4DataKeys()
Returns
Type | Description |
---|---|
IEnumerable<string> | An enumerable list of keys present for the requested type. |
GetFloat4DataValues()
Get a collection of the SplineData<T> values for this type.
Declaration
public IEnumerable<SplineData<float4>> GetFloat4DataValues()
Returns
Type | Description |
---|---|
IEnumerable<SplineData<float4>> | An enumerable list of values present for the requested type. |
GetFloatDataKeys()
Get a collection of the keys of embedded SplineData<T> for this type.
Declaration
public IEnumerable<string> GetFloatDataKeys()
Returns
Type | Description |
---|---|
IEnumerable<string> | An enumerable list of keys present for the requested type. |
GetFloatDataValues()
Get a collection of the SplineData<T> values for this type.
Declaration
public IEnumerable<SplineData<float>> GetFloatDataValues()
Returns
Type | Description |
---|---|
IEnumerable<SplineData<float>> | An enumerable list of values present for the requested type. |
GetIntDataKeys()
Get a collection of the keys of embedded SplineData<T> for this type.
Declaration
public IEnumerable<string> GetIntDataKeys()
Returns
Type | Description |
---|---|
IEnumerable<string> | An enumerable list of keys present for the requested type. |
GetIntDataValues()
Get a collection of the SplineData<T> values for this type.
Declaration
public IEnumerable<SplineData<int>> GetIntDataValues()
Returns
Type | Description |
---|---|
IEnumerable<SplineData<int>> | An enumerable list of values present for the requested type. |
GetLength()
Return the sum of all curve lengths, accounting for Closed state. Note that this value is not accounting for transform hierarchy. If you require length in world space use
Declaration
public float GetLength()
Returns
Type | Description |
---|---|
float | Returns the sum length of all curves composing this spline, accounting for closed state. |
Remarks
This value is cached. It is recommended to call this once in a non-performance critical path to ensure that the cache is valid.
See Also
GetObjectDataKeys()
Get a collection of the keys of embedded SplineData<T> for this type.
Declaration
public IEnumerable<string> GetObjectDataKeys()
Returns
Type | Description |
---|---|
IEnumerable<string> | An enumerable list of keys present for the requested type. |
GetObjectDataValues()
Get a collection of the SplineData<T> values for this type.
Declaration
public IEnumerable<SplineData<Object>> GetObjectDataValues()
Returns
Type | Description |
---|---|
IEnumerable<SplineData<Object>> | An enumerable list of values present for the requested type. |
GetOrCreateFloat4Data(string)
Returns a SplineData<T> for key
. If an instance matching the key and
type does not exist, a new entry is appended to the internal collection and returned.
Note that this is a reference to the stored SplineData<T>, not a copy. Any modifications to
this collection will affect the Spline data.
Declaration
public SplineData<float4> GetOrCreateFloat4Data(string key)
Parameters
Type | Name | Description |
---|---|---|
string | key | The string key value to search for. Only one instance of a key value can exist in an embedded SplineData<T> collection, however keys are unique to each data type. The same key can be re-used to store float data and Object data. |
Returns
Type | Description |
---|---|
SplineData<float4> | A SplineData<T> of the requested type. |
GetOrCreateFloatData(string)
Returns a SplineData<T> for key
. If an instance matching the key and
type does not exist, a new entry is appended to the internal collection and returned.
Note that this is a reference to the stored SplineData<T>, not a copy. Any modifications to
this collection will affect the Spline data.
Declaration
public SplineData<float> GetOrCreateFloatData(string key)
Parameters
Type | Name | Description |
---|---|---|
string | key | The string key value to search for. Only one instance of a key value can exist in an embedded SplineData<T> collection, however keys are unique to each data type. The same key can be re-used to store float data and Object data. |
Returns
Type | Description |
---|---|
SplineData<float> | A SplineData<T> of the requested type. |
GetOrCreateIntData(string)
Returns a SplineData<T> for key
. If an instance matching the key and
type does not exist, a new entry is appended to the internal collection and returned.
Note that this is a reference to the stored SplineData<T>, not a copy. Any modifications to
this collection will affect the Spline data.
Declaration
public SplineData<int> GetOrCreateIntData(string key)
Parameters
Type | Name | Description |
---|---|---|
string | key | The string key value to search for. Only one instance of a key value can exist in an embedded SplineData<T> collection, however keys are unique to each data type. The same key can be re-used to store float data and Object data. |
Returns
Type | Description |
---|---|
SplineData<int> | A SplineData<T> of the requested type. |
GetOrCreateObjectData(string)
Returns a SplineData<T> for key
. If an instance matching the key and
type does not exist, a new entry is appended to the internal collection and returned.
Note that this is a reference to the stored SplineData<T>, not a copy. Any modifications to
this collection will affect the Spline data.
Declaration
public SplineData<Object> GetOrCreateObjectData(string key)
Parameters
Type | Name | Description |
---|---|---|
string | key | The string key value to search for. Only one instance of a key value can exist in an embedded SplineData<T> collection, however keys are unique to each data type. The same key can be re-used to store float data and Object data. |
Returns
Type | Description |
---|---|
SplineData<Object> | A SplineData<T> of the requested type. |
GetSplineDataKeys(EmbeddedSplineDataType)
Get a collection of the keys of embedded SplineData<T> for this type.
Declaration
public IEnumerable<string> GetSplineDataKeys(EmbeddedSplineDataType type)
Parameters
Type | Name | Description |
---|---|---|
EmbeddedSplineDataType | type |
Returns
Type | Description |
---|---|
IEnumerable<string> | An enumerable list of keys present for the requested type. |
GetTangentMode(int)
Gets the TangentMode for a knot index.
Declaration
public TangentMode GetTangentMode(int index)
Parameters
Type | Name | Description |
---|---|---|
int | index | The index to retrieve TangentMode data for. |
Returns
Type | Description |
---|---|
TangentMode | A TangentMode for the knot at index. |
IndexOf(BezierKnot)
Return the first index of an element matching item.
Declaration
public int IndexOf(BezierKnot item)
Parameters
Type | Name | Description |
---|---|---|
BezierKnot | item | The knot to locate. |
Returns
Type | Description |
---|---|
int | The zero-based index of the knot, or -1 if not found. |
Insert(int, float3, TangentMode)
Creates a BezierKnot from a Unity.Mathematics.float3 knot position and inserts it at the specified index
.
When the tangent mode is set to Mirrored, Continuous, Broken, or Linear, the final tangent values are obtained from tangents initially computed using Autosmooth to ensure accuracy.
Declaration
public void Insert(int index, float3 knotPosition, TangentMode tangentMode = TangentMode.AutoSmooth)
Parameters
Type | Name | Description |
---|---|---|
int | index | The zero-based index to insert the new element at. |
float3 | knotPosition | The knot position to convert to a BezierKnot and insert in the spline. |
TangentMode | tangentMode | The TangentMode to apply to the new element. The default value is Autosmooth. |
Insert(int, BezierKnot)
Insert a BezierKnot at the specified index
.
Declaration
public void Insert(int index, BezierKnot knot)
Parameters
Type | Name | Description |
---|---|---|
int | index | The zero-based index to insert the new element. |
BezierKnot | knot | The BezierKnot to insert. |
Insert(int, BezierKnot, TangentMode)
Inserts a BezierKnot at the specified index
.
Declaration
public void Insert(int index, BezierKnot knot, TangentMode mode)
Parameters
Type | Name | Description |
---|---|---|
int | index | The zero-based index to insert the new element. |
BezierKnot | knot | The BezierKnot to insert. |
TangentMode | mode | The TangentMode to apply to this knot. Tangent modes are enforced when a knot value is set. |
Insert(int, BezierKnot, TangentMode, float)
Adds a BezierKnot at the specified index
.
Declaration
public void Insert(int index, BezierKnot knot, TangentMode mode, float tension)
Parameters
Type | Name | Description |
---|---|---|
int | index | The zero-based index to insert the new element. |
BezierKnot | knot | The BezierKnot to insert. |
TangentMode | mode | The TangentMode to apply to this knot. Tangent modes are enforced when a knot value is set. |
float | tension | The modifier value that is used to calculate the magnitude of tangents when the TangentMode is AutoSmooth. Valid values are between 0 and 1. A lower value results in sharper curves, whereas higher values appear more rounded. |
InsertRange(int, IEnumerable<float3>, TangentMode)
Creates BezierKnot from a range of Unity.Mathematics.float3 knot positions and inserts them at the specified index
.
When the tangent mode is set to Mirrored, Continuous, Broken, or Linear, the final tangent values are obtained from tangents initially computed using Autosmooth to ensure accuracy.
Declaration
public void InsertRange(int index, IEnumerable<float3> knotPositions, TangentMode tangentMode = TangentMode.AutoSmooth)
Parameters
Type | Name | Description |
---|---|---|
int | index | The zero-based index to insert the new elements at. |
IEnumerable<float3> | knotPositions | The range of knot positions to insert in the spline. |
TangentMode | tangentMode | The TangentMode to apply to this range of knot positions. The default value is Autosmooth. |
OnSplineChanged()
Invoked any time a spline property is modified.
Declaration
protected virtual void OnSplineChanged()
Remarks
In the editor this can be invoked many times per-frame. Prefer to use UnityEditor.Splines.EditorSplineUtility.AfterSplineWasModified when working with splines in the editor.
Remove(BezierKnot)
Removes the first matching knot.
Declaration
public bool Remove(BezierKnot item)
Parameters
Type | Name | Description |
---|---|---|
BezierKnot | item | The BezierKnot to locate and remove. |
Returns
Type | Description |
---|---|
bool | Returns true if a matching item was found and removed, false if no match was discovered. |
RemoveAt(int)
Removes the knot at the specified index.
Declaration
public void RemoveAt(int index)
Parameters
Type | Name | Description |
---|---|---|
int | index | The zero-based index of the element to remove. |
RemoveFloat4Data(string)
Remove a SplineData<T> value.
Declaration
public bool RemoveFloat4Data(string key)
Parameters
Type | Name | Description |
---|---|---|
string | key | The string key value to search for. Only one instance of a key value can exist in an embedded SplineData<T> collection, however keys are unique to each data type. The same key can be re-used to store float data and Object data. |
Returns
Type | Description |
---|---|
bool | Returns true if a matching SplineData<T> key value pair was found and removed, or false if no match was found. |
RemoveFloatData(string)
Remove a SplineData<T> value.
Declaration
public bool RemoveFloatData(string key)
Parameters
Type | Name | Description |
---|---|---|
string | key | The string key value to search for. Only one instance of a key value can exist in an embedded SplineData<T> collection, however keys are unique to each data type. The same key can be re-used to store float data and Object data. |
Returns
Type | Description |
---|---|
bool | Returns true if a matching SplineData<T> key value pair was found and removed, or false if no match was found. |
RemoveIntData(string)
Remove a SplineData<T> value.
Declaration
public bool RemoveIntData(string key)
Parameters
Type | Name | Description |
---|---|---|
string | key | The string key value to search for. Only one instance of a key value can exist in an embedded SplineData<T> collection, however keys are unique to each data type. The same key can be re-used to store float data and Object data. |
Returns
Type | Description |
---|---|
bool | Returns true if a matching SplineData<T> key value pair was found and removed, or false if no match was found. |
RemoveObjectData(string)
Remove a SplineData<T> value.
Declaration
public bool RemoveObjectData(string key)
Parameters
Type | Name | Description |
---|---|---|
string | key | The string key value to search for. Only one instance of a key value can exist in an embedded SplineData<T> collection, however keys are unique to each data type. The same key can be re-used to store float data and Object data. |
Returns
Type | Description |
---|---|
bool | Returns true if a matching SplineData<T> key value pair was found and removed, or false if no match was found. |
Resize(int)
Change the size of the BezierKnot list.
Declaration
public void Resize(int newSize)
Parameters
Type | Name | Description |
---|---|---|
int | newSize | The new size of the knots collection. |
SetAutoSmoothTension(int, float)
Sets the tension that is used to calculate the magnitude of tangents when the TangentMode is AutoSmooth. Valid values are between 0 and 1. A lower value results in sharper curves, whereas higher values appear more rounded.
Declaration
public void SetAutoSmoothTension(int index, float tension)
Parameters
Type | Name | Description |
---|---|---|
int | index | The knot index to set a tension value for. |
float | tension | Set the length of the tangent vectors. |
SetAutoSmoothTension(SplineRange, float)
Sets the tension that is used to calculate the magnitude of tangents when the TangentMode is AutoSmooth. Valid values are between 0 and 1. A lower value results in sharper curves, whereas higher values appear more rounded.
Declaration
public void SetAutoSmoothTension(SplineRange range, float tension)
Parameters
Type | Name | Description |
---|---|---|
SplineRange | range | The range of knot indices to set a tension value for. |
float | tension | Set the length of the tangent vectors. |
SetAutoSmoothTensionNoNotify(int, float)
Sets the tension that is used to calculate the magnitude of tangents when the TangentMode is AutoSmooth. Valid values are between 0 and 1. A lower value results in sharper curves, whereas higher values appear more rounded. No changed callbacks will be invoked.
Declaration
public void SetAutoSmoothTensionNoNotify(int index, float tension)
Parameters
Type | Name | Description |
---|---|---|
int | index | The knot index to set a tension value for. |
float | tension | Set the length of the tangent vectors for a knot set to AutoSmooth. |
SetAutoSmoothTensionNoNotify(SplineRange, float)
Set the tension that is used to calculate the magnitude of tangents when the TangentMode is AutoSmooth. Valid values are between 0 and 1. A lower value results in sharper curves, whereas higher values appear more rounded. No changed callbacks will be invoked.
Declaration
public void SetAutoSmoothTensionNoNotify(SplineRange range, float tension)
Parameters
Type | Name | Description |
---|---|---|
SplineRange | range | The range of knot indices to set a tension value for. |
float | tension | Set the length of the tangent vectors for a knot set to AutoSmooth. |
SetFloat4Data(string, SplineData<float4>)
Set the SplineData<T> for .
Declaration
public void SetFloat4Data(string key, SplineData<float4> value)
Parameters
Type | Name | Description |
---|---|---|
string | key | The string key value to search for. Only one instance of a key value can exist in an embedded SplineData<T> collection, however keys are unique to each data type. The same key can be re-used to store float data and Object data. |
SplineData<float4> | value | The SplineData<T> to set. This value will be copied. |
SetFloatData(string, SplineData<float>)
Set the SplineData<T> for .
Declaration
public void SetFloatData(string key, SplineData<float> value)
Parameters
Type | Name | Description |
---|---|---|
string | key | The string key value to search for. Only one instance of a key value can exist in an embedded SplineData<T> collection, however keys are unique to each data type. The same key can be re-used to store float data and Object data. |
SplineData<float> | value | The SplineData<T> to set. This value will be copied. |
SetIntData(string, SplineData<int>)
Set the SplineData<T> for .
Declaration
public void SetIntData(string key, SplineData<int> value)
Parameters
Type | Name | Description |
---|---|---|
string | key | The string key value to search for. Only one instance of a key value can exist in an embedded SplineData<T> collection, however keys are unique to each data type. The same key can be re-used to store float data and Object data. |
SplineData<int> | value | The SplineData<T> to set. This value will be copied. |
SetKnot(int, BezierKnot, BezierTangent)
Sets the value of a knot at index.
Declaration
public void SetKnot(int index, BezierKnot value, BezierTangent main = BezierTangent.Out)
Parameters
Type | Name | Description |
---|---|---|
int | index | The index of the BezierKnot to set. |
BezierKnot | value | The BezierKnot to set. |
BezierTangent | main | The tangent to prioritize if the tangents are modified to conform with the TangentMode set for this knot. |
SetKnotNoNotify(int, BezierKnot, BezierTangent)
Sets the value of a knot index without invoking any change callbacks.
Declaration
public void SetKnotNoNotify(int index, BezierKnot value, BezierTangent main = BezierTangent.Out)
Parameters
Type | Name | Description |
---|---|---|
int | index | The index of the BezierKnot to set. |
BezierKnot | value | The BezierKnot to set. |
BezierTangent | main | The tangent to prioritize if the tangents are modified to conform with the TangentMode set for this knot. |
SetObjectData(string, SplineData<Object>)
Set the SplineData<T> for .
Declaration
public void SetObjectData(string key, SplineData<Object> value)
Parameters
Type | Name | Description |
---|---|---|
string | key | The string key value to search for. Only one instance of a key value can exist in an embedded SplineData<T> collection, however keys are unique to each data type. The same key can be re-used to store float data and Object data. |
SplineData<Object> | value | The SplineData<T> to set. This value will be copied. |
SetTangentMode(int, TangentMode, BezierTangent)
Sets the TangentMode for a knot, and ensures that the rotation and tangent values match the behavior of the tangent mode. This function can modify the contents of the BezierKnot at the specified index.
Declaration
public void SetTangentMode(int index, TangentMode mode, BezierTangent main = BezierTangent.Out)
Parameters
Type | Name | Description |
---|---|---|
int | index | The index of the knot to set. |
TangentMode | mode | The mode to set. |
BezierTangent | main | The tangent direction to align both the In and Out tangent when assigning Continuous or Mirrored tangent mode. |
SetTangentMode(SplineRange, TangentMode, BezierTangent)
Sets the TangentMode for a series of knots, and ensures that the rotation and tangent values match the behavior of the tangent mode. This function can modify the contents of the BezierKnot at the specified indices.
Declaration
public void SetTangentMode(SplineRange range, TangentMode mode, BezierTangent main = BezierTangent.Out)
Parameters
Type | Name | Description |
---|---|---|
SplineRange | range | The range of knot indices to set. |
TangentMode | mode | The mode to set. |
BezierTangent | main | The tangent direction to align both the In and Out tangent with when Continuous or Mirrored tangent mode is assigned . |
SetTangentMode(TangentMode)
Sets the TangentMode for all knots on this spline.
Declaration
public void SetTangentMode(TangentMode mode)
Parameters
Type | Name | Description |
---|---|---|
TangentMode | mode | The TangentMode to apply to each knot. |
SetTangentModeNoNotify(int, TangentMode, BezierTangent)
Sets the TangentMode for a knot, and ensures that the rotation and tangent values match the behavior of the tangent mode. No changed callbacks will be invoked. This function can modify the contents of the BezierKnot at the specified index.
Declaration
public void SetTangentModeNoNotify(int index, TangentMode mode, BezierTangent main = BezierTangent.Out)
Parameters
Type | Name | Description |
---|---|---|
int | index | The index of the knot to set. |
TangentMode | mode | The mode to set. |
BezierTangent | main | The tangent direction to align both the In and Out tangent when assigning Continuous or Mirrored tangent mode. |
ToArray()
Create an array of spline knots.
Declaration
public BezierKnot[] ToArray()
Returns
Type | Description |
---|---|
BezierKnot[] | Return a new array copy of the knots collection. |
TryGetFloat4Data(string, out SplineData<float4>)
Retrieve a SplineData<T> reference for if it exists. Note that this is a reference to the stored SplineData<T>, not a copy. Any modifications to this collection will affect the Spline data.
Declaration
public bool TryGetFloat4Data(string key, out SplineData<float4> data)
Parameters
Type | Name | Description |
---|---|---|
string | key | The string key value to search for. Only one instance of a key value can exist in an embedded SplineData<T> collection, however keys are unique to each data type. The same key can be re-used to store float data and Object data. |
SplineData<float4> | data | The output SplineData<T> if the key is found. |
Returns
Type | Description |
---|---|
bool | True if the key and type combination are found, otherwise false. |
TryGetFloatData(string, out SplineData<float>)
Retrieve a SplineData<T> reference for if it exists. Note that this is a reference to the stored SplineData<T>, not a copy. Any modifications to this collection will affect the Spline data.
Declaration
public bool TryGetFloatData(string key, out SplineData<float> data)
Parameters
Type | Name | Description |
---|---|---|
string | key | The string key value to search for. Only one instance of a key value can exist in an embedded SplineData<T> collection, however keys are unique to each data type. The same key can be re-used to store float data and Object data. |
SplineData<float> | data | The output SplineData<T> if the key is found. |
Returns
Type | Description |
---|---|
bool | True if the key and type combination are found, otherwise false. |
TryGetIntData(string, out SplineData<int>)
Retrieve a SplineData<T> reference for if it exists. Note that this is a reference to the stored SplineData<T>, not a copy. Any modifications to this collection will affect the Spline data.
Declaration
public bool TryGetIntData(string key, out SplineData<int> data)
Parameters
Type | Name | Description |
---|---|---|
string | key | The string key value to search for. Only one instance of a key value can exist in an embedded SplineData<T> collection, however keys are unique to each data type. The same key can be re-used to store float data and Object data. |
SplineData<int> | data | The output SplineData<T> if the key is found. |
Returns
Type | Description |
---|---|
bool | True if the key and type combination are found, otherwise false. |
TryGetObjectData(string, out SplineData<Object>)
Retrieve a SplineData<T> reference for if it exists. Note that this is a reference to the stored SplineData<T>, not a copy. Any modifications to this collection will affect the Spline data.
Declaration
public bool TryGetObjectData(string key, out SplineData<Object> data)
Parameters
Type | Name | Description |
---|---|---|
string | key | The string key value to search for. Only one instance of a key value can exist in an embedded SplineData<T> collection, however keys are unique to each data type. The same key can be re-used to store float data and Object data. |
SplineData<Object> | data | The output SplineData<T> if the key is found. |
Returns
Type | Description |
---|---|
bool | True if the key and type combination are found, otherwise false. |
Warmup()
Ensure that all caches contain valid data. Call this to avoid unexpected performance costs when accessing spline data. Caches remain valid until any part of the spline state is modified.
Declaration
public void Warmup()
Events
Changed
Invoked any time a spline is modified.
Declaration
public static event Action<Spline, int, SplineModification> Changed
Event Type
Type | Description |
---|---|
Action<Spline, int, SplineModification> |
Remarks
First parameter is the target Spline that the event is raised for, second parameter is the knot index and the third parameter represents the type of change that occurred. If the event does not target a specific knot, the second parameter will have the value of -1.
In the editor this callback can be invoked many times per-frame. Prefer to use UnityEditor.Splines.EditorSplineUtility.AfterSplineWasModified when working with splines in the editor.