docs.unity3d.com
    Show / Hide Table of Contents

    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.

    Inheritance
    Object
    SplineData<T>
    Inherited Members
    Object.ToString()
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: UnityEngine.Splines
    Syntax
    [Serializable]
    public class SplineData<T> : IEnumerable<DataPoint<T>>, IEnumerable, ISplineModificationHandler
    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
    PathIndexUnit

    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
    PathIndexUnit

    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 t is represented as.

    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
    IEnumerable<T>.GetEnumerator()

    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. This is the index into the collection, not the PathIndexUnit.Knot.

    Single newIndex

    The new index (Knot) 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.

    Implements
    IEnumerable.GetEnumerator()

    Did you find this page useful? Please give it a rating:

    Thanks for rating this page!

    Report a problem on this page

    What kind of problem would you like to report?

    • This page needs code samples
    • Code samples do not work
    • Information is missing
    • Information is incorrect
    • Information is unclear or confusing
    • There is a spelling/grammar error on this page
    • Something else

    Thanks for letting us know! This page has been marked for review based on your feedback.

    If you have time, you can provide more information to help us fix the problem faster.

    Provide more information

    You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:

    You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:

    You've told us there is information missing from this page. Please tell us more about what's missing:

    You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:

    You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:

    You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:

    You've told us this page has a problem. Please tell us more about what's wrong:

    Thank you for helping to make the Unity documentation better!

    Your feedback has been submitted as a ticket for our documentation team to review.

    We are not able to reply to every ticket submitted.

    In This Article
    • Constructors
      • SplineData()
      • SplineData(T)
      • SplineData(IEnumerable<DataPoint<T>>)
    • Properties
      • Count
      • DefaultValue
      • Indexes
      • Item[Int32]
      • PathIndexUnit
    • Methods
      • Add(Single, T)
      • Add(DataPoint<T>)
      • AddDataPointWithDefaultValue(Single, Boolean)
      • Clear()
      • ConvertPathUnit<TSplineType>(TSplineType, PathIndexUnit)
      • Evaluate<TSpline, TInterpolator>(TSpline, Single, TInterpolator)
      • Evaluate<TSpline, TInterpolator>(TSpline, Single, PathIndexUnit, TInterpolator)
      • GetEnumerator()
      • GetNormalizedInterpolation<TSplineType>(TSplineType, Single)
      • MoveDataPoint(Int32, Single)
      • RemoveAt(Int32)
      • RemoveDataPoint(Single)
      • SetDataPoint(Int32, DataPoint<T>)
      • SetDataPointNoSort(Int32, DataPoint<T>)
      • SortIfNecessary()
    • Events
      • Changed
    • Explicit Interface Implementations
      • IEnumerable.GetEnumerator()
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023