Table of Contents

Class SplineController

Controller working with Splines

[AddComponentMenu("Curvy/Controllers/Spline Controller")]
public class SplineController : CurvyController
Inheritance
Object
Component
Behaviour
MonoBehaviour
DTVersionedMonoBehaviour
SplineController
Derived
Inherited Members

Constructors

SplineController()

public SplineController()

Fields

Switcher

protected readonly SplineController.SplineSwitcher Switcher

Field Value

SplineController.SplineSwitcher

Properties

AllowDirectionChange

Connections handling: When true, the controller will modify its direction to best fit the connected spline. Is used when ConnectionBehavior is equal to FollowUpSpline, RandomSpline, or FollowUpOtherwiseRandom

public bool AllowDirectionChange { get; set; }

Property Value

bool

ConnectionBehavior

Connections handling: What spline should the controller use when reaching a Connection

public SplineControllerConnectionBehavior ConnectionBehavior { get; set; }

Property Value

SplineControllerConnectionBehavior

ConnectionCustomSelector

Connections handling: A custom logic to select which connected spline to follow. Select a Script inheriting from SplineControllerConnectionBehavior. Is used when ConnectionBehavior is equal to Custom

public ConnectedControlPointsSelector ConnectionCustomSelector { get; set; }

Property Value

ConnectedControlPointsSelector

IsReady

Returns true if the controller has all it dependencies ready.

public override bool IsReady { get; }

Property Value

bool

Remarks

A controller that is not initialized and has IsReady true, will be initialized at the next update call (automatically each frame or manually through Refresh().

IsSwitching

Gets whether the Controller is switching splines

public bool IsSwitching { get; }

Property Value

bool

Length

Gets the source's length

public override float Length { get; }

Property Value

float

MaxAllowedDivergenceAngle

Connections handling: Maximum allowed divergence angle in degrees. Considered when MaxAllowedDivergenceAngle is true. Is used when ConnectionBehavior is equal to RandomSpline, or FollowUpOtherwiseRandom

public float MaxAllowedDivergenceAngle { get; set; }

Property Value

float

OnControlPointReached

Event raised when moving over a Control Point

public CurvySplineMoveEvent OnControlPointReached { get; set; }

Property Value

CurvySplineMoveEvent

OnEndReached

Event raised when reaching the extends (i.e. the start or end) of the source spline

public CurvySplineMoveEvent OnEndReached { get; set; }

Property Value

CurvySplineMoveEvent

OnPositionReachedList

Settings of events raised when moving over specific positions on the spline

public List<OnPositionReachedSettings> OnPositionReachedList { get; set; }

Property Value

List<OnPositionReachedSettings>

OnSwitch

Event raised while switching splines. Splines switching is triggered via the SwitchTo(CurvySpline, float, float) method.

public CurvySplineMoveEvent OnSwitch { get; set; }

Property Value

CurvySplineMoveEvent

RejectCurrentSpline

Connections handling: Whether the current spline should be excluded from the randomly selected splines. Is used when ConnectionBehavior is equal to RandomSpline, or FollowUpOtherwiseRandom

public bool RejectCurrentSpline { get; set; }

Property Value

bool

RejectTooDivergentSplines

Connections handling: Whether splines that diverge from the current spline with more than MaxAllowedDivergenceAngle should be excluded from the randomly selected splines. Is used when ConnectionBehavior is equal to RandomSpline, or FollowUpOtherwiseRandom

public bool RejectTooDivergentSplines { get; set; }

Property Value

bool

Spline

Gets or sets the spline to use

public virtual CurvySpline Spline { get; set; }

Property Value

CurvySpline

SwitchProgress

The ratio (value between 0 and 1) expressing the progress of the current spline switch. 0 means the switch just started, 1 means the switch ended. Its value is 0 if no spline switching is in progress. Spline switching is triggered by calling SwitchTo(CurvySpline, float, float)

public float SwitchProgress { get; }

Property Value

float

UseCache

Gets or sets whether spline's cache data should be used

public bool UseCache { get; set; }

Property Value

bool

Methods

AbsoluteToRelative(float)

Converts distance on source from absolute to relative position.

protected override float AbsoluteToRelative(float worldUnitDistance)

Parameters

worldUnitDistance float

distance in world units from the source start. Should be already clamped

Returns

float

relative distance in the range 0..1

Advance(float, float)

Advance the controller and return the new position. This method will do side effect operations if needed, like updating some internal state, or triggering events.

protected override void Advance(float speed, float deltaTime)

Parameters

speed float

controller's speed. Should be strictly positive

deltaTime float

the time that the controller should advance with. Should be strictly positive

CancelCurrentSwitch()

If is switching splines, cancels the current switch.

public void CancelCurrentSwitch()

ComputeTargetPositionAndRotation(out Vector3, out Vector3, out Vector3)

Gets the position and rotation of the controller, ignoring any damping or other interpolations

protected override void ComputeTargetPositionAndRotation(out Vector3 targetPosition, out Vector3 targetUp, out Vector3 targetForward)

Parameters

targetPosition Vector3
targetUp Vector3
targetForward Vector3

FinishCurrentSwitch()

If is switching splines, instantly finishes the current switch.

public void FinishCurrentSwitch()

GetAngleBetweenConnectedSplines(CurvySplineSegment, MovementDirection, CurvySplineSegment, bool)

Get the direction change, in degrees, of controller caused by the crossing of a connection.

public static float GetAngleBetweenConnectedSplines(CurvySplineSegment before, MovementDirection movementMode, CurvySplineSegment after, bool allowMovementModeChange)

Parameters

before CurvySplineSegment

The control point the controller is on before crossing the connection

movementMode MovementDirection

The movement mode the controller has before crossing the connection

after CurvySplineSegment

The control point the controller is on after crossing the connection

allowMovementModeChange bool

If true, the controller will change movemen mode to best fit the after control point. AllowDirectionChange

Returns

float

A positif angle in degrees

GetInterpolatedSourcePosition(float)

Retrieve the source global position for a given relative position (TF)

protected override Vector3 GetInterpolatedSourcePosition(float tf)

Parameters

tf float

Returns

Vector3

GetInterpolatedSourcePosition(float, out Vector3, out Vector3, out Vector3)

Retrieve the source global position, tangent and orientation for a given relative position (TF)

protected override void GetInterpolatedSourcePosition(float tf, out Vector3 interpolatedPosition, out Vector3 tangent, out Vector3 up)

Parameters

tf float
interpolatedPosition Vector3
tangent Vector3
up Vector3

GetOrientation(float)

Retrieve the source global Orientation/Up-Vector for a given relative position

protected override Vector3 GetOrientation(float tf)

Parameters

tf float

Returns

Vector3

GetTangent(float)

Gets global tangent for a given relative position

protected override Vector3 GetTangent(float tf)

Parameters

tf float

Returns

Vector3

InitializedApplyDeltaTime(float)

Advances the controller state by deltaTime seconds. Is called only for initialized controllers

protected override void InitializedApplyDeltaTime(float deltaTime)

Parameters

deltaTime float

RelativeToAbsolute(float)

Converts distance on source from relative to absolute position.

protected override float RelativeToAbsolute(float relativeDistance)

Parameters

relativeDistance float

relative distance from the source start. Should be already clamped

Returns

float

distance in world units from the source start

ResetPrePlayState()

protected override void ResetPrePlayState()

RestorePrePlayState()

protected override void RestorePrePlayState()

SavePrePlayState()

protected override void SavePrePlayState()

SimulateAdvance(ref float, ref MovementDirection, float, float)

Advance the controller and return the new position. Contrary to Advance(float, float), this method will not do any side effect operations, like updating some internal state, or triggering events

protected override void SimulateAdvance(ref float tf, ref MovementDirection direction, float speed, float deltaTime)

Parameters

tf float

the current virtual position (either TF or World Units)

direction MovementDirection

the current direction

speed float

controller's speed. Should be strictly positive

deltaTime float

the time that the controller should advance with. Should be strictly positive

SwitchTo(CurvySpline, float, float)

Start a spline switch. Should be called only on non stopped controllers.

public virtual void SwitchTo(CurvySpline destinationSpline, float destinationTf, float duration)

Parameters

destinationSpline CurvySpline

the target spline to switch to

destinationTf float

the target TF

duration float

duration of the switch phase

Remarks

While switching is not finished, movement on destination spline will not fire events nor consider connections