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
    [Serializable]
    public class Spline : ISpline

    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

    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.

    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
    Implements
    ISpline.Item[Int32]

    KnotCount

    Return the number of knots.

    Declaration
    public int KnotCount { get; }
    Property Value
    Type Description
    Int32
    Implements
    ISpline.KnotCount

    Knots

    A collection of BezierKnot.

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

    Methods

    AddKnot(BezierKnot)

    Append a knot to the end of the knot list.

    Declaration
    public void AddKnot(BezierKnot knot)
    Parameters
    Type Name Description
    BezierKnot knot

    The element to append.

    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.

    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)

    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()

    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(Spline, 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)

    InsertKnot(Int32, BezierKnot)

    Insert a BezierKnot at the specified index.

    Declaration
    public void InsertKnot(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.

    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.

    ToNativeArray(Allocator)

    Create a new native array of spline knots.

    Declaration
    public NativeArray<BezierKnot> ToNativeArray(Allocator allocator)
    Parameters
    Type Name Description
    Allocator allocator

    The allocator to construct the NativeArray with.

    Returns
    Type Description
    NativeArray<BezierKnot>

    Return a new array copy of the knots collection.

    ToNativeSpline(Allocator)

    Create a new NativeSpline copy of this spline. A NativeSpline contains a NativeArray of BezierKnot, and the closed state of a spline.

    Declaration
    public NativeSpline ToNativeSpline(Allocator allocator = Allocator.Temp)
    Parameters
    Type Name Description
    Allocator allocator

    The allocator to be passed when constructing the knots NativeArray.

    Returns
    Type Description
    NativeSpline

    A new NativeSpline representation of this Spline.

    ToNativeSpline(float4x4, Allocator)

    Create a new NativeSpline copy of this spline. A NativeSpline contains a NativeArray of BezierKnot, and the closed state of a spline.

    Declaration
    public NativeSpline ToNativeSpline(float4x4 transform, Allocator allocator = Allocator.Temp)
    Parameters
    Type Name Description
    float4x4 transform

    Transformation matrix to be applied to knots.

    Allocator allocator

    The allocator to be passed when constructing the knots NativeArray.

    Returns
    Type Description
    NativeSpline

    A new NativeSpline representation of this Spline.

    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 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.

    Extension Methods

    SplineUtility.EvaluatePosition<T>(T, Single)
    SplineUtility.EvaluateDirection<T>(T, Single)
    SplineUtility.EvaluateUpVector<T>(T, Single)
    SplineUtility.SplineToCurveInterpolation<T>(T, Single, out Single)
    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