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 keyframes.
Namespace: UnityEngine.Splines
Syntax
[Serializable]
public class SplineData<T>
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<Keyframe<T>>)
Create a new SplineData instance and initialize it with a collection of keys. Keys will be sorted and stored in ascending order by Time.
Declaration
public SplineData(IEnumerable<Keyframe<T>> keys)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<Keyframe<T>> | keys | A collection of Keyframes to initialize SplineData.` |
Properties
Count
How many keyframes the SplineData collection contains.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
Int32 |
Item[Int32]
Access a Keyframe<T> by index. Keyframes are sorted in ascending order by the Time value.
Declaration
public Keyframe<T> this[int index] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | The index of the keyframe to access. |
Property Value
Type | Description |
---|---|
Keyframe<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 Keyframe<T> 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 keyframe. |
Add(Keyframe<T>)
Append a Keyframe<T> to this collection.
Declaration
public void Add(Keyframe<T> key)
Parameters
Type | Name | Description |
---|---|---|
Keyframe<T> | key | The keyframe to append to the SplineData collection. |
Clear()
Remove all keyframes.
Declaration
public void Clear()
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. |
GetNormalizedTime(NativeSpline, Single)
Given a time value using a certain PathIndexUnit type, calculate the normalized time value regarding a specific spline.
Declaration
public float GetNormalizedTime(NativeSpline spline, float time)
Parameters
Type | Name | Description |
---|---|---|
NativeSpline | spline | The Spline to use for the conversion, this is necessary to compute Normalized and Distance PathIndexUnits. |
Single | time | The time to normalize in the original PathIndexUnit. |
Returns
Type | Description |
---|---|
Single | The normalized time. |
RemoveAt(Int32)
Remove a Keyframe<T> at index.
Declaration
public void RemoveAt(int index)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | The index to remove. |
SetKeyframe(Int32, Keyframe<T>)
Set the data for a Keyframe<T> at an index.
Declaration
public void SetKeyframe(int index, Keyframe<T> value)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | The Keyframe index. |
Keyframe<T> | value | The value to set. |
SetKeyframeNoSort(Int32, Keyframe<T>)
Declaration
public void SetKeyframeNoSort(int index, Keyframe<T> value)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | |
Keyframe<T> | value |
SortIfNecessary()
Declaration
public void SortIfNecessary()
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.