Routine

public class Routine;

Description

The Routine class is a convenience class for easily executing a Unity coroutine with progress callbacks. This can be helpful when animating an object over a duration, for example.

To use the routine class, create an instance of it and call Run like so:

 // Create a routine lasting duration seconds.
 Routine animation = new Routine(duration);

// Execute the routine. animation.Run(OnUpdate: (progress01) => { // The update action is called every frame for the routine's duration, // passing in a progress01 value. // e.g. Vector3.LerpUnclamped(startPos, endPos, progress01); }, OnComplete: () => { // The completion action is called after duration seconds. });

The Routine class will instantiate a game object to execute the coroutine, and destroy it upon completion.

Properties
delay The delay, in seconds, to wait before starting the routine after Run is called.
duration The duration of the routine, in seconds.
IsRunning Is the routine running?
updateMode The update mode of the routine. Can either be UnscaledTime or ScaledTime.
Methods
Routine Initializes a new instance of the Routine class.
Run Run the routine with the specified OnUpdate and OnComplete callbacks.
Stop Stop the routine.

delay

public float delay;

Description

The delay, in seconds, to wait before starting the routine after Run is called.


duration

public float duration;

Description

The duration of the routine, in seconds.


IsRunning

public bool IsRunning;

Description

Is the routine running?


updateMode

public RoutineUpdateMode updateMode;

Description

The update mode of the routine. Can either be UnscaledTime or ScaledTime.


Routine

public Routine(float duration = 1f, float delay = 0f, RoutineUpdateMode updateMode = RoutineUpdateMode.UnscaledTime);

Parameters

Name Description
duration The duration of the routine, in seconds.
delay The delay, in seconds, to wait before starting the routine after is called.
updateMode The update mode of the routine. Can either be UnscaledTime or ScaledTime.

Description

Initializes a new instance of the Routine class.


Run

public void Run(System.Action<float> OnUpdate = null, System.Action OnComplete = null);

Parameters

Name Description
OnUpdate The OnUpdate action. This will be called every frame with a progress value for the routine's duration.
OnComplete The OnComplete action. This will be called once when the routine has reached its duration.

Description

Run the routine with the specified OnUpdate and OnComplete callbacks.


Stop

public void Stop();

Description

Stop the routine.