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
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(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.` |
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.` |
Properties
Count
How many data points the SplineData collection contains.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
Int32 |
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<Single> |
Item[Int32]
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 |
---|---|---|
Int32 | 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(Single, T)
Append a DataPoint<TDataType> to this collection.
Declaration
public void Add(float t, T data)
Parameters
Type | Name | Description |
---|---|---|
Single | t | The interpolant relative to Spline. How this value is interpreted is dependent on UnityEngine.Splines.SplineData`1.get_PathIndexUnit. |
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 |
---|---|
Int32 | The index of the inserted dataPoint. |
AddDataPointWithDefaultValue(Single, Boolean)
Append a DataPoint<TDataType> with default value to this collection.
Declaration
public int AddDataPointWithDefaultValue(float t, bool useDefaultValue = false)
Parameters
Type | Name | Description |
---|---|---|
Single | t | The interpolant relative to Spline. How this value is interpreted is dependent on UnityEngine.Splines.SplineData`1.get_PathIndexUnit. |
Boolean | useDefaultValue | If true will use UnityEngine.Splines.SplineData`1.m_DefaultValue to set the value, otherwise will interpolate the value regarding the closest DataPoints. |
Returns
Type | Description |
---|---|
Int32 | 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, Single, 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. |
Single | 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. |
Evaluate<TSpline, TInterpolator>(TSpline, Single, 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. |
Single | 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. |
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. |
Implements
GetNormalizedInterpolation<TSplineType>(TSplineType, Single)
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. |
Single | t | The time to normalize in the original PathIndexUnit. |
Returns
Type | Description |
---|---|
Single | The normalized time. |
Type Parameters
Name | Description |
---|---|
TSplineType | The Spline type. |
MoveDataPoint(Int32, Single)
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 |
---|---|---|
Int32 | index | The index of the DataPoint<TDataType> to move. |
Single | newIndex | The new index for this DataPoint<TDataType>. |
Returns
Type | Description |
---|---|
Int32 | The index of the modified DataPoint<TDataType>. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
RemoveAt(Int32)
Remove a DataPoint<TDataType> at index.
Declaration
public void RemoveAt(int index)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | The index to remove. |
RemoveDataPoint(Single)
Remove a DataPoint<TDataType> from this collection, if one exists.
Declaration
public bool RemoveDataPoint(float t)
Parameters
Type | Name | Description |
---|---|---|
Single | t | The interpolant relative to Spline. How this value is interpreted is dependent on UnityEngine.Splines.SplineData`1.get_PathIndexUnit. |
Returns
Type | Description |
---|---|
Boolean | True is deleted, false otherwise. |
SetDataPoint(Int32, 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 |
---|---|---|
Int32 | 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(Int32, 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(Int32, 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 |
---|---|---|
Int32 | index | The DataPoint index. |
DataPoint<T> | value | The value to set. |
Remarks
Use this method as an altenative to SetDataPoint(Int32, 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(Int32, 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 RegisterSplineDataChanged<T>(Action<SplineData<T>>) when working with splines in the editor.
Explicit Interface Implementations
IEnumerable.GetEnumerator()
Returns an enumerator that iterates through the DataPoints collection.
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator | An IEnumerator{DataPoint{T}} for this collection. |