Class SplineController
- Namespace
- FluffyUnderware.Curvy.Controllers
Controller working with Splines
[AddComponentMenu("Curvy/Controllers/Spline Controller")]
public class SplineController : CurvyController
- Inheritance
-
ObjectComponentBehaviourMonoBehaviourDTVersionedMonoBehaviourSplineController
- Derived
- Inherited Members
Constructors
SplineController()
public SplineController()
Fields
Switcher
protected readonly SplineController.SplineSwitcher Switcher
Field Value
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
ConnectionBehavior
Connections handling: What spline should the controller use when reaching a Connection
public SplineControllerConnectionBehavior ConnectionBehavior { get; set; }
Property Value
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
IsReady
Returns true if the controller has all it dependencies ready.
public override bool IsReady { get; }
Property Value
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
Length
Gets the source's length
public override float Length { get; }
Property Value
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
OnControlPointReached
Event raised when moving over a Control Point
public CurvySplineMoveEvent OnControlPointReached { get; set; }
Property Value
OnEndReached
Event raised when reaching the extends (i.e. the start or end) of the source spline
public CurvySplineMoveEvent OnEndReached { get; set; }
Property Value
OnPositionReachedList
Settings of events raised when moving over specific positions on the spline
public List<OnPositionReachedSettings> OnPositionReachedList { get; set; }
Property Value
OnSwitch
Event raised while switching splines. Splines switching is triggered via the SwitchTo(CurvySpline, float, float) method.
public CurvySplineMoveEvent OnSwitch { get; set; }
Property Value
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
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
Spline
Gets or sets the spline to use
public virtual CurvySpline Spline { get; set; }
Property Value
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
UseCache
Gets or sets whether spline's cache data should be used
public bool UseCache { get; set; }
Property Value
Methods
AbsoluteToRelative(float)
Converts distance on source from absolute to relative position.
protected override float AbsoluteToRelative(float worldUnitDistance)
Parameters
worldUnitDistance
floatdistance 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 trigerring events.
protected override void Advance(float speed, float deltaTime)
Parameters
speed
floatcontroller's speed. Should be strictely positive
deltaTime
floatthe time that the controller should advance with. Should be strictely 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
Vector3targetUp
Vector3targetForward
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
CurvySplineSegmentThe control point the controller is on before crossing the connection
movementMode
MovementDirectionThe movement mode the controller has before crossing the connection
after
CurvySplineSegmentThe control point the controller is on after crossing the connection
allowMovementModeChange
boolIf true, the controller will change movemen mode to best fit the after control point. AllowDirectionChange
Returns
- float
A positif angle in degrees
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
floatinterpolatedPosition
Vector3tangent
Vector3up
Vector3
GetInterpolatedSourcePosition(float)
Retrieve the source global position for a given relative position (TF)
protected override Vector3 GetInterpolatedSourcePosition(float tf)
Parameters
tf
float
Returns
- 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
floatrelative 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 trigerring events
protected override void SimulateAdvance(ref float tf, ref MovementDirection direction, float speed, float deltaTime)
Parameters
tf
floatthe current virtual position (either TF or World Units)
direction
MovementDirectionthe current direction
speed
floatcontroller's speed. Should be strictely positive
deltaTime
floatthe time that the controller should advance with. Should be strictely 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
CurvySplinethe target spline to switch to
destinationTf
floatthe target TF
duration
floatduration of the switch phase
Remarks
While switching is not finished, movement on destination spline will not fire events nor consider connections