Class SplineData<T>
The SplineData{T} class is used to store information relative to a Spline without coupling data directly to the Spline class. SplineData can store any type of data, and provides options for how to index DataPoints.
Inherited Members
Namespace: UnityEngine.Splines
Assembly: Unity.Splines.dll
Syntax
[Serializable]
public class SplineData<T> : IEnumerable<DataPoint<T>>, IEnumerable
Type Parameters
Name | Description |
---|---|
T | The type of data to store. |
Constructors
SplineData()
Create a new SplineData instance.
Declaration
public SplineData()
SplineData(IEnumerable<DataPoint<T>>)
Create a new SplineData instance and initialize it with a collection of data points. DataPoints will be sorted and stored in ascending order by Index.
Declaration
public SplineData(IEnumerable<DataPoint<T>> dataPoints)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<DataPoint<T>> | dataPoints | A collection of DataPoints to initialize SplineData.` |
SplineData(T)
Create a new SplineData instance with a single value in it.
Declaration
public SplineData(T init)
Parameters
Type | Name | Description |
---|---|---|
T | init | A single value to add to the spline data at t = 0.` |
Properties
Count
How many data points the SplineData collection contains.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
int |
DefaultValue
Default value to use when a new DataPoint is automatically added.
Declaration
public T DefaultValue { get; set; }
Property Value
Type | Description |
---|---|
T |
See Also
Indexes
The DataPoint Indexes of the current SplineData.
Declaration
public IEnumerable<float> Indexes { get; }
Property Value
Type | Description |
---|---|
IEnumerable<float> |
this[int]
Access a DataPoint<TDataType> by index. DataPoints are sorted in ascending order by the Index value.
Declaration
public DataPoint<T> this[int index] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
int | index | The index of the DataPoint to access. |
Property Value
Type | Description |
---|---|
DataPoint<T> |
PathIndexUnit
PathIndexUnit defines how SplineData will interpret 't' values when interpolating data.
Declaration
public PathIndexUnit PathIndexUnit { get; set; }
Property Value
Type | Description |
---|---|
PathIndexUnit |
See Also
Methods
Add(float, T)
Append a DataPoint<TDataType> to this collection.
Declaration
public void Add(float t, T data)
Parameters
Type | Name | Description |
---|---|---|
float | t | The interpolant relative to Spline. How this value is interpreted is dependent on PathIndexUnit.get. |
T | data | The data to store in the created data point. |
Add(DataPoint<T>)
Append a DataPoint<TDataType> to this collection.
Declaration
public int Add(DataPoint<T> dataPoint)
Parameters
Type | Name | Description |
---|---|---|
DataPoint<T> | dataPoint | The data point to append to the SplineData collection. |
Returns
Type | Description |
---|---|
int | The index of the inserted dataPoint. |
AddDataPointWithDefaultValue(float, bool)
Append a DataPoint<TDataType> with default value to this collection.
Declaration
public int AddDataPointWithDefaultValue(float t, bool useDefaultValue = false)
Parameters
Type | Name | Description |
---|---|---|
float | t | The interpolant relative to Spline. How this value is interpreted is dependent on PathIndexUnit.get. |
bool | useDefaultValue | If true will use m_DefaultValue to set the value, otherwise will interpolate the value regarding the closest DataPoints. |
Returns
Type | Description |
---|---|
int | The index of the inserted dataPoint. |
Clear()
Remove all data points.
Declaration
public void Clear()
ConvertPathUnit<TSplineType>(TSplineType, PathIndexUnit)
Given a spline and a target PathIndex Unit, convert the SplineData to a new PathIndexUnit without changing the final positions on the Spline.
Declaration
public void ConvertPathUnit<TSplineType>(TSplineType spline, PathIndexUnit toUnit) where TSplineType : ISpline
Parameters
Type | Name | Description |
---|---|---|
TSplineType | spline | The Spline to use for the conversion, this is necessary to compute most of PathIndexUnits. |
PathIndexUnit | toUnit | The unit to convert SplineData to. |
Type Parameters
Name | Description |
---|---|
TSplineType | The Spline type. |
Evaluate<TSpline, TInterpolator>(TSpline, float, PathIndexUnit, TInterpolator)
Calculate an interpolated value at a given 't' along a spline.
Declaration
public T Evaluate<TSpline, TInterpolator>(TSpline spline, float t, PathIndexUnit indexUnit, TInterpolator interpolator) where TSpline : ISpline where TInterpolator : IInterpolator<T>
Parameters
Type | Name | Description |
---|---|---|
TSpline | spline | The Spline to interpolate. |
float | t | The interpolator value. How this is interpreted is defined by PathIndexUnit. |
PathIndexUnit | indexUnit | The PathIndexUnit that |
TInterpolator | interpolator | The IInterpolator<T> to use. A collection of commonly used interpolators are available in the UnityEngine.Splines.Interpolators namespace. |
Returns
Type | Description |
---|---|
T | An interpolated value. |
Type Parameters
Name | Description |
---|---|
TSpline | The Spline type. |
TInterpolator | The IInterpolator type. |
Evaluate<TSpline, TInterpolator>(TSpline, float, TInterpolator)
Calculate an interpolated value at a given 't' along a spline.
Declaration
public T Evaluate<TSpline, TInterpolator>(TSpline spline, float t, TInterpolator interpolator) where TSpline : ISpline where TInterpolator : IInterpolator<T>
Parameters
Type | Name | Description |
---|---|---|
TSpline | spline | The Spline to interpolate. |
float | t | The interpolator value. How this is interpreted is defined by PathIndexUnit. |
TInterpolator | interpolator | The IInterpolator<T> to use. A collection of commonly used interpolators are available in the UnityEngine.Splines.Interpolators namespace. |
Returns
Type | Description |
---|---|
T | An interpolated value. |
Type Parameters
Name | Description |
---|---|
TSpline | The Spline type. |
TInterpolator | The IInterpolator type. |
GetEnumerator()
Returns an enumerator that iterates through the DataPoints collection.
Declaration
public IEnumerator<DataPoint<T>> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<DataPoint<T>> | An IEnumerator{DataPoint{T}} for this collection. |
GetNormalizedInterpolation<TSplineType>(TSplineType, float)
Given a time value using a certain PathIndexUnit type, calculate the normalized time value regarding a specific spline.
Declaration
public float GetNormalizedInterpolation<TSplineType>(TSplineType spline, float t) where TSplineType : ISpline
Parameters
Type | Name | Description |
---|---|---|
TSplineType | spline | The Spline to use for the conversion, this is necessary to compute Normalized and Distance PathIndexUnits. |
float | t | The time to normalize in the original PathIndexUnit. |
Returns
Type | Description |
---|---|
float | The normalized time. |
Type Parameters
Name | Description |
---|---|
TSplineType | The Spline type. |
MoveDataPoint(int, float)
Move a DataPoint<TDataType> (if it exists) from this collection, from one index to the another.
Declaration
public int MoveDataPoint(int index, float newIndex)
Parameters
Type | Name | Description |
---|---|---|
int | index | The index of the DataPoint<TDataType> to move. This is the index into the collection, not the PathIndexUnit.Knot. |
float | newIndex | The new index (Knot) for this DataPoint<TDataType>. |
Returns
Type | Description |
---|---|
int | The index of the modified DataPoint<TDataType>. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
RemoveAt(int)
Remove a DataPoint<TDataType> at index.
Declaration
public void RemoveAt(int index)
Parameters
Type | Name | Description |
---|---|---|
int | index | The index to remove. |
RemoveDataPoint(float)
Remove a DataPoint<TDataType> from this collection, if one exists.
Declaration
public bool RemoveDataPoint(float t)
Parameters
Type | Name | Description |
---|---|---|
float | t | The interpolant relative to Spline. How this value is interpreted is dependent on PathIndexUnit.get. |
Returns
Type | Description |
---|---|
bool | True is deleted, false otherwise. |
SetDataPoint(int, DataPoint<T>)
Set the data for a DataPoint<TDataType> at an index.
Declaration
public void SetDataPoint(int index, DataPoint<T> value)
Parameters
Type | Name | Description |
---|---|---|
int | index | The DataPoint index. |
DataPoint<T> | value | The value to set. |
Remarks
Using this method will search the DataPoint list and invoke the Changed callback every time. This may be inconvenient when setting multiple DataPoints during the same frame. In this case, consider calling SetDataPointNoSort(int, DataPoint<T>) for each DataPoint, followed by a single call to SortIfNecessary(). Note that the call to SortIfNecessary() is optional and can be omitted if DataPoint sorting is not required and the Changed callback should not be invoked.
SetDataPointNoSort(int, DataPoint<T>)
Set the data for a DataPoint<TDataType> at an index.
Declaration
public void SetDataPointNoSort(int index, DataPoint<T> value)
Parameters
Type | Name | Description |
---|---|---|
int | index | The DataPoint index. |
DataPoint<T> | value | The value to set. |
Remarks
Use this method as an altenative to SetDataPoint(int, DataPoint<T>) when manual control over DataPoint sorting and the Changed callback is required. See also SortIfNecessary().
SortIfNecessary()
Triggers sorting of the DataPoint<TDataType> list if the data is dirty.
Declaration
public void SortIfNecessary()
Remarks
Call this after a single or series of calls to SetDataPointNoSort(int, DataPoint<T>). This will trigger DataPoint sort and invoke the Changed callback. This method has two main use cases: to prevent frequent Changed callback calls within the same frame and to reduce multiple DataPoints list searches to a single sort in performance critical paths.
Events
Changed
Invoked any time a SplineData is modified.
Declaration
public event Action Changed
Event Type
Type | Description |
---|---|
Action |
Remarks
In the editor this can be invoked many times per-frame. Prefer to use UnityEditor.Splines.EditorSplineUtility.RegisterSplineDataChanged when working with splines in the editor.