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
    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 Spline : ISpline, IReadOnlyList<BezierKnot>, IReadOnlyCollection<BezierKnot>, IList<BezierKnot>, ICollection<BezierKnot>, IEnumerable<BezierKnot>, IEnumerable

    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
    Implements
    IReadOnlyCollection<T>.Count
    ICollection<T>.Count

    IsReadOnly

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

    Declaration
    public bool IsReadOnly { get; }
    Property Value
    Type Description
    Boolean
    Implements
    ICollection<T>.IsReadOnly

    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
    IReadOnlyList<T>.Item[Int32]
    IList<T>.Item[Int32]

    Knots

    A collection of BezierKnot.

    Declaration
    public IEnumerable<BezierKnot> Knots { get; set; }
    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.

    Implements
    ICollection<T>.Add(T)

    Add(BezierKnot, TangentMode)

    Adds a knot to the spline.

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

    The BezierKnot to add.

    TangentMode mode

    The tangent mode for this knot.

    Add(BezierKnot, TangentMode, Single)

    Adds a knot to the spline.

    Declaration
    public void Add(BezierKnot item, TangentMode mode, float tension)
    Parameters
    Type Name Description
    BezierKnot item

    The BezierKnot to add.

    TangentMode mode

    The tangent mode for this knot.

    Single tension

    The modifier value that is used to calculate the magnitude of tangents when the TangentMode is AutoSmooth. Valid values are between 0 and 1. A lower value results in sharper curves, whereas higher values appear more rounded.

    Clear()

    Remove all knots from the spline.

    Declaration
    public void Clear()
    Implements
    ICollection<T>.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.

    Implements
    ICollection<T>.Contains(T)

    Copy(Spline)

    Copy the values from copyFrom to this spline.

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

    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.

    Implements
    ICollection<T>.CopyTo(T[], Int32)

    GetAutoSmoothTension(Int32)

    Gets the tension value for the requested index.

    Declaration
    public float GetAutoSmoothTension(int index)
    Parameters
    Type Name Description
    Int32 index

    The knot index to get a tension value for.

    Returns
    Type Description
    Single

    Returns the tension value for the requested index.

    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.

    Implements
    IEnumerable<T>.GetEnumerator()

    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

    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)

    GetTangentMode(Int32)

    Gets the TangentMode for a knot index.

    Declaration
    public TangentMode GetTangentMode(int index)
    Parameters
    Type Name Description
    Int32 index

    The index to retrieve TangentMode data for.

    Returns
    Type Description
    TangentMode

    A TangentMode for the knot at index.

    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.

    Implements
    IList<T>.IndexOf(T)

    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.

    Implements
    IList<T>.Insert(Int32, T)

    Insert(Int32, BezierKnot, TangentMode)

    Inserts a BezierKnot at the specified index.

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

    The zero-based index to insert the new element.

    BezierKnot knot

    The BezierKnot to insert.

    TangentMode mode

    The TangentMode to apply to this knot. Tangent modes are enforced when a knot value is set.

    Insert(Int32, BezierKnot, TangentMode, Single)

    Adds a BezierKnot at the specified index.

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

    The zero-based index to insert the new element.

    BezierKnot knot

    The BezierKnot to insert.

    TangentMode mode

    The TangentMode to apply to this knot. Tangent modes are enforced when a knot value is set.

    Single tension

    The modifier value that is used to calculate the magnitude of tangents when the TangentMode is AutoSmooth. Valid values are between 0 and 1. A lower value results in sharper curves, whereas higher values appear more rounded.

    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 UnityEditor.Splines.EditorSplineUtility.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.

    Implements
    ICollection<T>.Remove(T)

    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.

    Implements
    IList<T>.RemoveAt(Int32)

    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.

    SetAutoSmoothTension(Int32, Single)

    Sets the tension that is used to calculate the magnitude of tangents when the TangentMode is AutoSmooth. Valid values are between 0 and 1. A lower value results in sharper curves, whereas higher values appear more rounded.

    Declaration
    public void SetAutoSmoothTension(int index, float tension)
    Parameters
    Type Name Description
    Int32 index

    The knot index to set a tension value for.

    Single tension

    Set the length of the tangent vectors.

    SetAutoSmoothTension(SplineRange, Single)

    Sets the tension that is used to calculate the magnitude of tangents when the TangentMode is AutoSmooth. Valid values are between 0 and 1. A lower value results in sharper curves, whereas higher values appear more rounded.

    Declaration
    public void SetAutoSmoothTension(SplineRange range, float tension)
    Parameters
    Type Name Description
    SplineRange range

    The range of knot indices to set a tension value for.

    Single tension

    Set the length of the tangent vectors.

    SetAutoSmoothTensionNoNotify(Int32, Single)

    Sets the tension that is used to calculate the magnitude of tangents when the TangentMode is AutoSmooth. Valid values are between 0 and 1. A lower value results in sharper curves, whereas higher values appear more rounded. No changed callbacks will be invoked.

    Declaration
    public void SetAutoSmoothTensionNoNotify(int index, float tension)
    Parameters
    Type Name Description
    Int32 index

    The knot index to set a tension value for.

    Single tension

    Set the length of the tangent vectors for a knot set to AutoSmooth.

    SetAutoSmoothTensionNoNotify(SplineRange, Single)

    Set the tension that is used to calculate the magnitude of tangents when the TangentMode is AutoSmooth. Valid values are between 0 and 1. A lower value results in sharper curves, whereas higher values appear more rounded. No changed callbacks will be invoked.

    Declaration
    public void SetAutoSmoothTensionNoNotify(SplineRange range, float tension)
    Parameters
    Type Name Description
    SplineRange range

    The range of knot indices to set a tension value for.

    Single tension

    Set the length of the tangent vectors for a knot set to AutoSmooth.

    SetKnot(Int32, BezierKnot, BezierTangent)

    Sets the value of a knot at index.

    Declaration
    public void SetKnot(int index, BezierKnot value, BezierTangent main = BezierTangent.Out)
    Parameters
    Type Name Description
    Int32 index

    The index of the BezierKnot to set.

    BezierKnot value

    The BezierKnot to set.

    BezierTangent main

    The tangent to prioritize if the tangents are modified to conform with the TangentMode set for this knot.

    SetKnotNoNotify(Int32, BezierKnot, BezierTangent)

    Sets the value of a knot index without invoking any change callbacks.

    Declaration
    public void SetKnotNoNotify(int index, BezierKnot value, BezierTangent main = BezierTangent.Out)
    Parameters
    Type Name Description
    Int32 index

    The index of the BezierKnot to set.

    BezierKnot value

    The BezierKnot to set.

    BezierTangent main

    The tangent to prioritize if the tangents are modified to conform with the TangentMode set for this knot.

    SetTangentMode(Int32, TangentMode, BezierTangent)

    Sets the TangentMode for a knot, and ensures that the rotation and tangent values match the behavior of the tangent mode. This function can modify the contents of the BezierKnot at the specified index.

    Declaration
    public void SetTangentMode(int index, TangentMode mode, BezierTangent main = BezierTangent.Out)
    Parameters
    Type Name Description
    Int32 index

    The index of the knot to set.

    TangentMode mode

    The mode to set.

    BezierTangent main

    The tangent direction to align both the In and Out tangent when assigning Continuous or Mirrored tangent mode.

    SetTangentMode(SplineRange, TangentMode, BezierTangent)

    Sets the TangentMode for a series of knots, and ensures that the rotation and tangent values match the behavior of the tangent mode. This function can modify the contents of the BezierKnot at the specified indices.

    Declaration
    public void SetTangentMode(SplineRange range, TangentMode mode, BezierTangent main = BezierTangent.Out)
    Parameters
    Type Name Description
    SplineRange range

    The range of knot indices to set.

    TangentMode mode

    The mode to set.

    BezierTangent main

    The tangent direction to align both the In and Out tangent with when Continuous or Mirrored tangent mode is assigned .

    SetTangentMode(TangentMode)

    Sets the TangentMode for all knots on this spline.

    Declaration
    public void SetTangentMode(TangentMode mode)
    Parameters
    Type Name Description
    TangentMode mode

    The TangentMode to apply to each knot.

    SetTangentModeNoNotify(Int32, TangentMode, BezierTangent)

    Sets the TangentMode for a knot, and ensures that the rotation and tangent values match the behavior of the tangent mode. No changed callbacks will be invoked. This function can modify the contents of the BezierKnot at the specified index.

    Declaration
    public void SetTangentModeNoNotify(int index, TangentMode mode, BezierTangent main = BezierTangent.Out)
    Parameters
    Type Name Description
    Int32 index

    The index of the knot to set.

    TangentMode mode

    The mode to set.

    BezierTangent main

    The tangent direction to align both the In and Out tangent when assigning Continuous or Mirrored tangent mode.

    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 any time a spline is modified.

    Declaration
    public static event Action<Spline, int, SplineModification> Changed
    Event Type
    Type Description
    Action<Spline, Int32, SplineModification>
    Remarks

    First parameter is the target Spline that the event is raised for, second parameter is the knot index and the third parameter represents the type of change that occured. If the event does not target a specific knot, the second parameter will have the value of -1.

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

    See Also
    SplineModification

    Explicit Interface Implementations

    IEnumerable.GetEnumerator()

    Gets an enumerator that iterates through the BezierKnot collection.

    Declaration
    IEnumerator IEnumerable.GetEnumerator()
    Returns
    Type Description
    IEnumerator

    An IEnumerator that is used to iterate the BezierKnot collection.

    Implements
    IEnumerable.GetEnumerator()

    Extension Methods

    SplineUtility.Evaluate<T>(T, Single, out float3, out float3, out float3)
    SplineUtility.EvaluatePosition<T>(T, Single)
    SplineUtility.EvaluateTangent<T>(T, Single)
    SplineUtility.EvaluateUpVector<T>(T, Single)
    SplineUtility.EvaluateAcceleration<T>(T, Single)
    SplineUtility.EvaluateCurvature<T>(T, Single)
    SplineUtility.EvaluateCurvatureCenter<T>(T, Single)
    SplineUtility.SplineToCurveT<T>(T, Single, out Single)
    SplineUtility.CurveToSplineT<T>(T, Single)
    SplineUtility.CalculateLength<T>(T, float4x4)
    SplineUtility.GetCurveCount<T>(T)
    SplineUtility.GetBounds<T>(T)
    SplineUtility.GetBounds<T>(T, float4x4)
    SplineUtility.GetPointAtLinearDistance<T>(T, Single, Single, out Single)
    SplineUtility.ConvertIndexUnit<T>(T, Single, PathIndexUnit)
    SplineUtility.ConvertIndexUnit<T>(T, Single, PathIndexUnit, PathIndexUnit)
    SplineUtility.PreviousIndex<T>(T, Int32)
    SplineUtility.NextIndex<T>(T, Int32)
    SplineUtility.Previous<T>(T, Int32)
    SplineUtility.Next<T>(T, Int32)
    SplineDataHandles.DataPointHandles<TSpline, TData>(TSpline, SplineData<TData>, Boolean)
    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