Table of Contents

Class CurvyController

Controller base class

[ExecuteAlways]
public abstract class CurvyController : DTVersionedMonoBehaviour
Inheritance
Object
Component
Behaviour
MonoBehaviour
DTVersionedMonoBehaviour
CurvyController
Derived

Constructors

CurvyController()

public CurvyController()

Fields

ControllerNotReadyMessage

An error message used in various assertions

protected const string ControllerNotReadyMessage = "The controller is not yet ready"

Field Value

string

LockedRotation

When OrientationMode is None, and LockRotation is true, this field is the value of the locked rotation, the one that will be assigned all the time to the controller

protected Quaternion LockedRotation

Field Value

Quaternion

PrePlayDirection

The MovementDirection of the controller when started playing

protected MovementDirection PrePlayDirection

Field Value

MovementDirection

PrePlayPosition

The position of the controller when started playing

protected float PrePlayPosition

Field Value

float

State

The state (Playing, paused or stopped) of the controller CurvyController.CurvyControllerState

protected CurvyController.CurvyControllerState State

Field Value

CurvyController.CurvyControllerState

UpdateIn

public CurvyUpdateMethod UpdateIn

Field Value

CurvyUpdateMethod

onInitialized

[SerializeField]
protected ControllerEvent onInitialized

Field Value

ControllerEvent

Properties

AbsolutePosition

Gets or sets the absolute position on the source, respecting Clamping

public float AbsolutePosition { get; set; }

Property Value

float

Clamping

Gets or sets what to do when the source's end is reached

public CurvyClamping Clamping { get; set; }

Property Value

CurvyClamping

Damper

[NotNull]
protected CurvyController.OrientationDamper Damper { get; }

Property Value

CurvyController.OrientationDamper

DirectionDampingTime

If non zero, the direction vector (forward) of the controlled object will not be updated instantly, but using a damping effect that will last the specified amount of time.

public float DirectionDampingTime { get; set; }

Property Value

float

IgnoreDirection

Should the controller's orientation ignore the movement direction?

public bool IgnoreDirection { get; set; }

Property Value

bool

IsReady

Returns true if the controller has all it dependencies ready.

public abstract 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().

Length

Gets the source's length

public abstract float Length { get; }

Property Value

float

LockRotation

Used only when OrientationMode is equal to None When true, the controller will enforce the rotation to not change

public bool LockRotation { get; set; }

Property Value

bool

MotionConstraints

Defines what motions are to be frozen

public MotionConstraints MotionConstraints { get; set; }

Property Value

MotionConstraints

MoveMode

Gets or sets the movement mode to use

public CurvyController.MoveModeEnum MoveMode { get; set; }

Property Value

CurvyController.MoveModeEnum

MovementDirection

Gets or sets the movement direction

public MovementDirection MovementDirection { get; set; }

Property Value

MovementDirection

OffsetAngle

Gets or sets the angle to offset (-180° to 180° off Orientation)

public float OffsetAngle { get; set; }

Property Value

float

OffsetCompensation

Adjusts speed to match the change of travel distance due to offset

public bool OffsetCompensation { get; set; }

Property Value

bool

OffsetRadius

Gets or sets the offset radius

public float OffsetRadius { get; set; }

Property Value

float

OnInitialized

Invoked each time the controller finishes initialization

public ControllerEvent OnInitialized { get; }

Property Value

ControllerEvent

OrientationAxis

Gets or sets the axis to apply the rotation to

public OrientationAxisEnum OrientationAxis { get; set; }

Property Value

OrientationAxisEnum

OrientationMode

Gets or sets how to apply rotation

public OrientationModeEnum OrientationMode { get; set; }

Property Value

OrientationModeEnum

PlayAutomatically

Gets or sets whether to start playing automatically

public bool PlayAutomatically { get; set; }

Property Value

bool

PlayState

The state (Playing, paused or stopped) of the controller

public CurvyController.CurvyControllerState PlayState { get; }

Property Value

CurvyController.CurvyControllerState

Position

Gets or sets the position on the source (relative or absolute, depending on MoveMode), respecting Clamping

public float Position { get; set; }

Property Value

float

PositionMode

Gets or sets the position mode to use

public CurvyPositionMode PositionMode { get; set; }

Property Value

CurvyPositionMode

RelativePosition

Gets or sets the relative position on the source, respecting Clamping

public float RelativePosition { get; set; }

Property Value

float

Rigidbody

Gets the rigidbody being controlled by this controller.

public virtual Rigidbody Rigidbody { get; }

Property Value

Rigidbody
See Also

Rigidbody2D

Gets the 2d rigidbody being controlled by this controller.

public virtual Rigidbody2D Rigidbody2D { get; }

Property Value

Rigidbody2D
See Also

ShouldDisablePositionSlider

The position slider is disabled in the inspector when this property returns true

protected virtual bool ShouldDisablePositionSlider { get; }

Property Value

bool

ShowOffsetSection

Whether the controller should display the CurvyController properties under the Offset section or not.

protected virtual bool ShowOffsetSection { get; }

Property Value

bool

ShowOrientationSection

Whether the controller should display the CurvyController properties under the Orientation section or not.

protected virtual bool ShowOrientationSection { get; }

Property Value

bool

Speed

Gets or sets the speed either in world units or relative, depending on MoveMode

public float Speed { get; set; }

Property Value

float

TargetComponent

The component controlled by the controller

public TargetComponent TargetComponent { get; set; }

Property Value

TargetComponent

TimeSinceLastUpdate

When in Play mode, the controller update happens only in Update or Late Update of Fixed Update, so the time since last update is always equal to Time.deltaTime When in Edit mode, the controller update happens at various points, including the editor's update, so we compute the time since last update using a time stamp

protected float TimeSinceLastUpdate { get; }

Property Value

float

Transform

Gets the transform being controlled by this controller.

public virtual Transform Transform { get; }

Property Value

Transform
See Also

UpDampingTime

If non zero, the up vector of the controlled object will not be updated instantly, but using a damping effect that will last the specified amount of time.

public float UpDampingTime { get; set; }

Property Value

float

UseOffset

Whether this controller uses Offsetting or not

protected bool UseOffset { get; }

Property Value

bool

isInitialized

Whether or not the controller is initialized. Initialization happens before first usage

protected bool isInitialized { get; }

Property Value

bool

Methods

AbsoluteToRelative(float)

Converts distance on source from absolute to relative position.

protected abstract 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 abstract 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

ApplyDeltaTime(float)

Advances the controller state by deltaTime seconds, without waiting for the automatic per frame update. Can initialize or deinitialize the controller if the right conditions are met.

public void ApplyDeltaTime(float deltaTime)

Parameters

deltaTime float

ApplyOffset(Vector3, Vector3, Vector3, float, float)

Returns the position of the controller after applying an offset

protected static Vector3 ApplyOffset(Vector3 position, Vector3 tangent, Vector3 up, float offsetAngle, float offsetRadius)

Parameters

position Vector3

The controller's position

tangent Vector3

The tangent at the controller's position

up Vector3

The Up direction at the controller's position

offsetAngle float

OffsetAngle

offsetRadius float

OffsetRadius

Returns

Vector3

BindEvents()

Binds any external events

protected virtual void BindEvents()

ComputeOffsetCompensatedSpeed(float)

Returns the Speed after applying Offset Compensation OffsetCompensation

protected float ComputeOffsetCompensatedSpeed(float deltaTime)

Parameters

deltaTime float

Time since last update

Returns

float

ComputeTargetPositionAndRotation(out Vector3, out Vector3, out Vector3)

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

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

Parameters

targetPosition Vector3
targetUp Vector3
targetForward Vector3

Deinitialize()

protected virtual void Deinitialize()

GetClampedPosition(float, CurvyPositionMode, CurvyClamping, float)

Return the clamped position

protected static float GetClampedPosition(float position, CurvyPositionMode positionMode, CurvyClamping clampingMode, float length)

Parameters

position float
positionMode CurvyPositionMode
clampingMode CurvyClamping
length float

Returns

float

GetInterpolatedSourcePosition(float)

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

protected abstract 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 abstract void GetInterpolatedSourcePosition(float tf, out Vector3 interpolatedPosition, out Vector3 tangent, out Vector3 up)

Parameters

tf float
interpolatedPosition Vector3
tangent Vector3
up Vector3

GetMaxPosition(CurvyPositionMode)

Returns the maximal valid position value using the given CurvyPositionMode

protected float GetMaxPosition(CurvyPositionMode positionMode)

Parameters

positionMode CurvyPositionMode

Returns

float

GetOrientation(float)

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

protected abstract Vector3 GetOrientation(float tf)

Parameters

tf float

Returns

Vector3

GetPositionAndRotation(out Vector3, out Quaternion)

Gets the current position and rotation of the target component

protected virtual void GetPositionAndRotation(out Vector3 position, out Quaternion rotation)

Parameters

position Vector3
rotation Quaternion
See Also

GetTangent(float)

Gets global tangent for a given relative position

protected abstract Vector3 GetTangent(float tf)

Parameters

tf float

Returns

Vector3

Initialize()

protected virtual void Initialize()

InitializedApplyDeltaTime(float)

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

protected virtual void InitializedApplyDeltaTime(float deltaTime)

Parameters

deltaTime float

OnAfterDeserialize()

Implementation of UnityEngine.ISerializationCallbackReceiver Called automatically by Unity, is not meant to be called by Curvy's users

public virtual void OnAfterDeserialize()

OnBeforeSerialize()

Implementation of UnityEngine.ISerializationCallbackReceiver Called automatically by Unity, is not meant to be called by Curvy's users

public void OnBeforeSerialize()

Pause()

Pauses the controller. To unpause it call Play()

public void Pause()

Play()

Plays the controller. Calling this method while the controller is playing will have no effect.

public void Play()

Refresh()

Forces the controller to update its state, without waiting for the automatic per frame update. Can initialize or deinitialize the controller if the right conditions are met.

public void Refresh()

RelativeToAbsolute(float)

Converts distance on source from relative to absolute position.

protected abstract 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 virtual void ResetPrePlayState()

RestorePrePlayState()

protected virtual void RestorePrePlayState()

SavePrePlayState()

protected virtual void SavePrePlayState()

SetFromString(string)

Event-friendly helper that sets a field or property value

public void SetFromString(string fieldAndValue)

Parameters

fieldAndValue string

e.g. "MyValue=42"

SetPositionAndRotation(Vector3, Quaternion)

Sets a new position and rotation to the target component

protected virtual void SetPositionAndRotation(Vector3 position, Quaternion rotation)

Parameters

position Vector3
rotation Quaternion
See Also

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

Stop()

Stops the controller, and restore its position (and other relevant states) to its state when starting playing

public void Stop()

TeleportBy(float, MovementDirection)

Teleports the controller to by a specific distance, while handling events triggering and connections.

public void TeleportBy(float distance, MovementDirection direction)

Parameters

distance float

A positive distance

direction MovementDirection

Direction of teleportation

Remarks

Internally, the teleport is handled as a movement of high speed on small time (0.001s). This will call ApplyDeltaTime(float) with that small amount of time.

TeleportTo(float)

Teleports the controller to a specific position, while handling events triggering and connections.

public void TeleportTo(float newPosition)

Parameters

newPosition float

Remarks

Internally, the teleport is handled as a movement of high speed on small time (0.001s). This will call ApplyDeltaTime(float) with that small amount of time.

UnbindEvents()

Unbinds any external events

protected virtual void UnbindEvents()

UserAfterInit()

Called after the controller is initialized

protected virtual void UserAfterInit()

UserAfterUpdate()

Called after the controller has updated it's position or rotation

protected virtual void UserAfterUpdate()