Default Actions
Coding Style wiki
The ActionSystem ships with 5 default actions (all inheriting ActionBase). By composing them you can build all kinds of run groups (sequences, parallels, delays, callbacks), nesting them freely (a sequence containing parallels, a parallel containing sequences), and finally start them with an ActionRunner.
| Namespace | OxGKit.ActionSystem |
| Type | SequenceAction, ParallelAction, ParallelDelayAction, DelayAction, DelegateAction (all inherit ActionBase) |
| Source | SequenceAction.cs, ParallelAction.cs, ParallelDelayAction.cs, DelayAction.cs, DelegateAction.cs |
using OxGKit.ActionSystem;
Quick Start
using OxGKit.ActionSystem;
using UnityEngine;
// Parallel group: runs simultaneously, finishes when all are done
var parAction = new ParallelAction("Burst");
parAction
.AddAction(DelayAction.CreateDelayAction(1f, () => Debug.Log("Delay 1s done")))
.AddAction(DelayAction.CreateDelayAction(2f, () => Debug.Log("Delay 2s done")));
// Sequence group: runs one by one (Step 1 -> 1s delay -> Step 2 -> parallel group)
var seqAction = new SequenceAction("OpenFlow");
seqAction
.AddAction(DelegateAction.CreateDelegateAction(() => Debug.Log("Step 1")))
.AddAction(DelayAction.CreateDelayAction(1f))
.AddAction(DelegateAction.CreateDelegateAction(() => Debug.Log("Step 2")))
.AddAction(parAction);
// Start with an ActionRunner (pumped by the owner via DriveUpdate)
this._runner.RunAction(seqAction);
General Rules
Composition Rules
- All default actions inherit ActionBase and can be nested into each other; every
AddActionis chainable. - Every default action provides the four constructors
(),(int uid),(string name),(string name, int uid), so you can set a custom name (log identification) and UID (for removal viaRemoveAction).
Attention The composite actions (SequenceAction / ParallelAction / ParallelDelayAction) run internally with SetDuration(-1) - their completion is decided by the child actions (they finish only when all children are done).
Action Overview
| Action | Description |
|---|---|
| SequenceAction | Sequence action - runs child actions one by one. |
| ParallelAction | Parallel action - runs all child actions simultaneously. |
| ParallelDelayAction | Staggered parallel action - starts children one by one with a delay interval, then runs them in parallel. |
| DelayAction | Delay action - finishes after the given seconds (with an optional end callback). |
| DelegateAction | Delegate action - invokes a callback on start (with an optional delay). |
SequenceAction
public class SequenceAction : ActionBase
Sequence action: runs child actions one at a time in the order they were added; the next action starts only after the previous one is all done (IsAllDone). The sequence finishes once every child action is done (if it starts with no actions, it is marked done immediately).
Constructors
public SequenceAction()
public SequenceAction(int uid)
public SequenceAction(string name)
public SequenceAction(string name, int uid)
Method Overview
| Method | Description |
|---|---|
| AddAction | Adds an action (compose before starting). |
| QueueAction | Queues an action (append while running). |
| RemoveAction | Removes an action by UID. |
AddAction
public SequenceAction AddAction(ActionBase action)
Adds an action to the preparing list (the same instance is never added twice). Returns the sequence itself, so calls are chainable.
Attention AddAction must be called before the sequence starts (starting moves the preparing list into the pending queue); to append actions while the sequence is already running, use QueueAction instead.
var seqAction = new SequenceAction("OpenFlow");
seqAction
.AddAction(DelegateAction.CreateDelegateAction(() => Debug.Log("Step 1")))
.AddAction(DelayAction.CreateDelayAction(1f))
.AddAction(DelegateAction.CreateDelegateAction(() => Debug.Log("Step 2")));
this._runner.RunAction(seqAction);
QueueAction
public SequenceAction QueueAction(ActionBase action)
Queues an action while the sequence is running (chainable); it is merged into the pending queue on the next update and runs after the existing actions in order.
RemoveAction
public void RemoveAction(int uid)
Removes an action by uid from the current/pending/queued caches (marks it all done and prints a removal report).
ParallelAction
public class ParallelAction : ActionBase
Parallel action: starts all child actions at once and updates them in parallel; it finishes once all child actions are done (if it starts with no actions, it is marked done immediately).
Constructors
public ParallelAction()
public ParallelAction(int uid)
public ParallelAction(string name)
public ParallelAction(string name, int uid)
AddAction
public ParallelAction AddAction(ActionBase action)
Adds an action (the same instance is never added twice). Returns the parallel action itself, so calls are chainable; must be called before the parallel action starts.
var parAction = new ParallelAction("Burst");
parAction
.AddAction(DelayAction.CreateDelayAction(1f, () => Debug.Log("Delay 1s done")))
.AddAction(DelayAction.CreateDelayAction(2f, () => Debug.Log("Delay 2s done")));
this._runner.RunAction(parAction);
ParallelDelayAction
public class ParallelDelayAction : ActionBase
Staggered parallel action: similar to ParallelAction, but child actions are started one by one with a delayTime interval between starts (staggered starts, delayed internally with UniTask), then updated in parallel; it finishes once all child actions are done.
Constructors
public ParallelDelayAction()
public ParallelDelayAction(int uid)
public ParallelDelayAction(string name)
public ParallelDelayAction(string name, int uid)
public ParallelDelayAction(float delayTime)
delayTime is the start interval in seconds between child actions (staggering only happens when it is greater than 0).
AddAction
public ParallelDelayAction AddAction(ActionBase action)
Adds an action (the same instance is never added twice). Returns the staggered parallel action itself, so calls are chainable; must be called before the action starts.
// Start one child action every 0.2 seconds, then run them in parallel
var staggerAction = new ParallelDelayAction(0.2f);
staggerAction
.AddAction(DelegateAction.CreateDelegateAction(() => Debug.Log("Spawn 1")))
.AddAction(DelegateAction.CreateDelegateAction(() => Debug.Log("Spawn 2")))
.AddAction(DelegateAction.CreateDelegateAction(() => Debug.Log("Spawn 3")));
this._runner.RunAction(staggerAction);
DelayAction
public class DelayAction : ActionBase
Delay action: finishes after delayTime seconds and invokes the optional onEndAction callback on completion (fired once, then cleared).
Members
| Member | Description |
|---|---|
public float delayTime | Delay in seconds (set as the duration in OnStart). |
public Action onEndAction | End callback (fired once on completion, then cleared). |
Constructors
public DelayAction()
public DelayAction(int uid)
public DelayAction(string name)
public DelayAction(string name, int uid)
CreateDelayAction
public static DelayAction CreateDelayAction(float delayTime, Action onEndAction = null)
[Factory] Creates a delay action with the given delay seconds and end callback.
// Invoke the callback after a 1.5 second delay
var delayAction = DelayAction.CreateDelayAction(1.5f, () => Debug.Log("1.5s done"));
DelegateAction
public class DelegateAction : ActionBase
Delegate action: invokes the onAction callback on start (fired once, then cleared).
Members
| Member | Description |
|---|---|
public event Action onAction | Delegate callback (fired once on start, then cleared). |
Constructors
public DelegateAction()
public DelegateAction(int uid)
public DelegateAction(string name)
public DelegateAction(string name, int uid)
CreateDelegateAction
public static ActionBase CreateDelegateAction(Action onAction, float delayTime = 0f)
[Factory] Creates a delegate action and automatically hooks MarkAsDone into the callback chain (the action finishes right after the callback fires). When delayTime is greater than 0, it returns a SequenceAction wrapping a DelayAction + DelegateAction (delay first, then invoke the callback).
Attention With delayTime greater than 0 the return value is a SequenceAction wrapper (static type ActionBase) - do not cast it to DelegateAction.
Reminder Prefer the CreateDelegateAction factory; if you new DelegateAction() yourself and subscribe to onAction, the action runs with SetDuration(-1) internally, so you must call MarkAsDone() inside the callback to finish it.
// Invoke the callback immediately
var callback = DelegateAction.CreateDelegateAction(() => Debug.Log("Hello"));
// Invoke the callback after a 1 second delay (returns a SequenceAction wrapper)
var delayedCallback = DelegateAction.CreateDelegateAction(() => Debug.Log("Hello Delayed"), 1f);