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<Data |
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 Data
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 |
---|---|
Data |
PathIndexUnit
PathIndexUnit defines how SplineData will interpret 't' values when interpolating data.
Declaration
public PathIndexUnit PathIndexUnit { get; set; }
Property Value
Type | Description |
---|---|
Path |
See Also
Methods
Add(float, T)
Append a Data
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 Path |
T | data | The data to store in the created data point. |
Add(DataPoint<T>)
Append a Data
Declaration
public int Add(DataPoint<T> dataPoint)
Parameters
Type | Name | Description |
---|---|---|
Data |
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 Data
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 Path |
bool | useDefaultValue | If true will use m_Default |
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 |
---|---|---|
TSpline |
spline | The Spline to use for the conversion, this is necessary to compute most of PathIndexUnits. |
Path |
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 Path |
Path |
indexUnit | The Path |
TInterpolator | interpolator | The IInterpolator<T> to use. A collection of commonly used
interpolators are available in the Unity |
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 Path |
TInterpolator | interpolator | The IInterpolator<T> to use. A collection of commonly used
interpolators are available in the Unity |
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<Data |
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 |
---|---|---|
TSpline |
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 Data
Declaration
public int MoveDataPoint(int index, float newIndex)
Parameters
Type | Name | Description |
---|---|---|
int | index | The index of the Data |
float | newIndex | The new index (Knot) for this Data |
Returns
Type | Description |
---|---|
int | The index of the modified Data |
Exceptions
Type | Condition |
---|---|
Argument |
Thrown when the specified |
RemoveAt(int)
Remove a Data
Declaration
public void RemoveAt(int index)
Parameters
Type | Name | Description |
---|---|---|
int | index | The index to remove. |
RemoveDataPoint(float)
Remove a Data
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 Path |
Returns
Type | Description |
---|---|
bool | True is deleted, false otherwise. |
SetDataPoint(int, DataPoint<T>)
Set the data for a Data
Declaration
public void SetDataPoint(int index, DataPoint<T> value)
Parameters
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 Set
SetDataPointNoSort(int, DataPoint<T>)
Set the data for a Data
Declaration
public void SetDataPointNoSort(int index, DataPoint<T> value)
Parameters
Remarks
Use this method as an altenative to Set
SortIfNecessary()
Triggers sorting of the Data
Declaration
public void SortIfNecessary()
Remarks
Call this after a single or series of calls to Set
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.