docs.unity3d.com
    Show / Hide Table of Contents

    Class Spline

    The Spline class is a collection of BezierKnot, the closed/open state, and editing representation.

    Inheritance
    Object
    Spline
    RollercoasterTrack
    Namespace: UnityEngine.Splines
    Syntax
    public class Spline : object, ISpline, IReadOnlyList<BezierKnot>, IList<BezierKnot>

    Constructors

    Spline()

    Default constructor creates a spline with no knots, not closed.

    Declaration
    public Spline()

    Spline(IEnumerable<BezierKnot>, Boolean)

    Create a spline from a collection of BezierKnot.

    Declaration
    public Spline(IEnumerable<BezierKnot> knots, bool closed = false)
    Parameters
    Type Name Description
    IEnumerable<BezierKnot> knots

    A collection of BezierKnot.

    Boolean closed

    Whether the spline is open (has a start and end point) or closed (forms an unbroken loop).

    Spline(Int32, Boolean)

    Create a spline with a pre-allocated knot capacity.

    Declaration
    public Spline(int knotCapacity, bool closed = false)
    Parameters
    Type Name Description
    Int32 knotCapacity

    The capacity of the knot collection.

    Boolean closed

    Whether the spline is open (has a start and end point) or closed (forms an unbroken loop).

    Properties

    Closed

    Whether the spline is open (has a start and end point) or closed (forms an unbroken loop).

    Declaration
    public bool Closed { get; set; }
    Property Value
    Type Description
    Boolean
    Implements
    ISpline.Closed

    Count

    Return the number of knots.

    Declaration
    public int Count { get; }
    Property Value
    Type Description
    Int32

    EditType

    The SplineType that this spline should be presented as to the user.

    Declaration
    public SplineType EditType { get; set; }
    Property Value
    Type Description
    SplineType
    Remarks

    Internally all splines are stored as a collection of bezier knots, and when editing converted or displayed with the handles appropriate to the editable type.

    IsReadOnly

    Returns true if this Spline is read-only, false if it is mutable.

    Declaration
    public bool IsReadOnly { get; }
    Property Value
    Type Description
    Boolean

    Item[Int32]

    Get or set the knot at index.

    Declaration
    public BezierKnot this[int index] { get; set; }
    Parameters
    Type Name Description
    Int32 index

    The zero-based index of the element to get or set.

    Property Value
    Type Description
    BezierKnot

    Knots

    A collection of BezierKnot.

    Declaration
    public IEnumerable<BezierKnot> Knots { get; }
    Property Value
    Type Description
    IEnumerable<BezierKnot>

    Methods

    Add(BezierKnot)

    Adds a knot to the spline.

    Declaration
    public void Add(BezierKnot item)
    Parameters
    Type Name Description
    BezierKnot item

    The BezierKnot to add.

    Clear()

    Remove all knots from the spline.

    Declaration
    public void Clear()

    Contains(BezierKnot)

    Return true if a knot is present in the spline.

    Declaration
    public bool Contains(BezierKnot item)
    Parameters
    Type Name Description
    BezierKnot item

    The BezierKnot to locate.

    Returns
    Type Description
    Boolean

    Returns true if the knot is found, false if it is not present.

    Copy(Spline)

    Copy the values from toCopy to this spline.

    Declaration
    public void Copy(Spline toCopy)
    Parameters
    Type Name Description
    Spline toCopy

    The Spline to copy property data from.

    CopyTo(BezierKnot[], Int32)

    Copies the contents of the knot list to an array starting at an index.

    Declaration
    public void CopyTo(BezierKnot[] array, int arrayIndex)
    Parameters
    Type Name Description
    BezierKnot[] array

    The destination array to place the copied item in.

    Int32 arrayIndex

    The zero-based index to copy.

    GetCurve(Int32)

    Get a BezierCurve from a knot index.

    Declaration
    public BezierCurve GetCurve(int index)
    Parameters
    Type Name Description
    Int32 index

    The knot index that serves as the first control point for this curve.

    Returns
    Type Description
    BezierCurve

    A BezierCurve formed by the knot at index and the next knot.

    Implements
    ISpline.GetCurve(Int32)

    GetCurveInterpolation(Int32, Single)

    Return the normalized interpolation (t) corresponding to a distance on a BezierCurve.

    Declaration
    public float GetCurveInterpolation(int curveIndex, float curveDistance)
    Parameters
    Type Name Description
    Int32 curveIndex

    The zero-based index of the curve.

    Single curveDistance

    The curve-relative distance to convert to an interpolation ratio (also referred to as 't').

    Returns
    Type Description
    Single

    The normalized interpolation ratio associated to distance on the designated curve.

    Implements
    ISpline.GetCurveInterpolation(Int32, Single)

    GetCurveLength(Int32)

    Return the length of a curve.

    Declaration
    public float GetCurveLength(int index)
    Parameters
    Type Name Description
    Int32 index
    Returns
    Type Description
    Single
    Implements
    ISpline.GetCurveLength(Int32)
    See Also
    Warmup()
    GetLength()

    GetEnumerator()

    Get an enumerator that iterates through the BezierKnot collection.

    Declaration
    public IEnumerator<BezierKnot> GetEnumerator()
    Returns
    Type Description
    IEnumerator<BezierKnot>

    An IEnumerator that is used to iterate the BezierKnot collection.

    GetLength()

    Return the sum of all curve lengths, accounting for Closed state. Note that this value is not accounting for transform hierarchy. If you require length in world space use CalculateLength<T>(T, float4x4).

    Declaration
    public float GetLength()
    Returns
    Type Description
    Single

    Returns the sum length of all curves composing this spline, accounting for closed state.

    Implements
    ISpline.GetLength()
    Remarks

    This value is cached. It is recommended to call this once in a non-performance critical path to ensure that the cache is valid.

    See Also
    Warmup()
    GetCurveLength(Int32)

    IndexOf(BezierKnot)

    Return the first index of an element matching item.

    Declaration
    public int IndexOf(BezierKnot item)
    Parameters
    Type Name Description
    BezierKnot item

    The knot to locate.

    Returns
    Type Description
    Int32

    The zero-based index of the knot, or -1 if not found.

    Insert(Int32, BezierKnot)

    Insert a BezierKnot at the specified index.

    Declaration
    public void Insert(int index, BezierKnot knot)
    Parameters
    Type Name Description
    Int32 index

    The zero-based index to insert the new element.

    BezierKnot knot

    The BezierKnot to insert.

    OnSplineChanged()

    Invoked any time a spline property is modified.

    Declaration
    protected virtual void OnSplineChanged()
    Remarks

    In the editor this can be invoked many times per-frame. Prefer to use afterSplineWasModified when working with splines in the editor.

    Remove(BezierKnot)

    Removes the first matching knot.

    Declaration
    public bool Remove(BezierKnot item)
    Parameters
    Type Name Description
    BezierKnot item

    The BezierKnot to locate and remove.

    Returns
    Type Description
    Boolean

    Returns true if a matching item was found and removed, false if no match was discovered.

    RemoveAt(Int32)

    Removes the knot at the specified index.

    Declaration
    public void RemoveAt(int index)
    Parameters
    Type Name Description
    Int32 index

    The zero-based index of the element to remove.

    Resize(Int32)

    Change the size of the BezierKnot list.

    Declaration
    public void Resize(int newSize)
    Parameters
    Type Name Description
    Int32 newSize

    The new size of the knots collection.

    ToArray()

    Create an array of spline knots.

    Declaration
    public BezierKnot[] ToArray()
    Returns
    Type Description
    BezierKnot[]

    Return a new array copy of the knots collection.

    Warmup()

    Ensure that all caches contain valid data. Call this to avoid unexpected performance costs when accessing spline data. Caches remain valid until any part of the spline state is modified.

    Declaration
    public void Warmup()

    Events

    changed

    Invoked in the editor any time a spline property 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 when working with splines in the editor.

    Back to top
    Terms of use
    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