ActionRunner
Coding Style wiki
ActionRunner is the action runner of the ActionSystem (a plain C# class, not a MonoBehaviour). It is responsible for starting (RunAction), queuing (QueueAction), removing (RemoveAction), and releasing (Release) actions. It has no update loop of its own - an owner (a MonoBehaviour Update, an updater, etc.) must call DriveUpdate(dt) to pump it.
| Namespace | OxGKit.ActionSystem |
| Type | public class ActionRunner |
| Source | ActionRunner.cs |
using OxGKit.ActionSystem;
Reminder Since v1.0.3 the public update entry point is DriveUpdate(dt) (consistent with the Drive naming across OxGKit systems); OnUpdate(dt) is now protected and driven by DriveUpdate.
Quick Start
using OxGKit.ActionSystem;
using UnityEngine;
public class FeatureController : MonoBehaviour
{
private ActionRunner _runner;
private void Awake()
{
// Create the runner (name it for log identification)
this._runner = new ActionRunner("FeatureRunner");
}
private void Start()
{
// Compose a sequence
var seqAction = new SequenceAction("OpenFlow");
seqAction
.AddAction(DelegateAction.CreateDelegateAction(() => Debug.Log("Step 1")))
.AddAction(DelayAction.CreateDelayAction(1f))
.AddAction(DelegateAction.CreateDelegateAction(() => Debug.Log("Step 2")));
// Start the action (resets the runner)
this._runner.RunAction(seqAction);
}
private void Update()
{
// Pumped by the owner
this._runner.DriveUpdate(Time.deltaTime);
}
private void OnDestroy()
{
// Release on exit so pending callbacks cannot hit released objects
this._runner.Release();
}
}
General Rules
Driving Rules
Important A runner must be pumped by a single owner through DriveUpdate: without a driver, actions do not advance; pumped twice in the same frame, they run at double speed.
Important When the owner (scene/UI/feature) exits, call Release to clear the actions, so pending callbacks cannot hit released objects.
Done Reports
Reminder Done and removed actions are reported through the LoggingSystem logger OxGKit.ActionSystem.Logger; enable it in the LoggingSystem configuration to trace runs.
Members
| Member | Description |
|---|---|
public string name | Runner name (defaults to ActionRunner), used for log identification. |
Constructors
public ActionRunner()
public ActionRunner(string name)
Creates a runner; name can be specified for log identification.
Action Management
Method Overview
| Method | Description |
|---|---|
| DriveUpdate | Called by the owner to pump the runner. |
| RunAction | Resets the runner and starts the action immediately. |
| QueueAction | Queues an action (started on the next update). |
| RemoveAction | Removes an action by UID. |
| Release | Clears all actions. |
DriveUpdate
public void DriveUpdate(float dt)
Called by the owner (a MonoBehaviour Update, etc.) to pump the runner: updates all running actions, removes finished (IsAllDone) actions and prints their done reports, then starts any queued actions.
private void Update()
{
this._runner.DriveUpdate(Time.deltaTime);
}
RunAction
public void RunAction(ActionBase action)
Resets the runner (clears running/queued actions), then starts the given action immediately.
Attention RunAction resets the runner before starting (replace behavior); to append an action without clearing existing ones, use QueueAction instead.
QueueAction
public ActionRunner QueueAction(ActionBase action)
Enqueues an action (the same action instance is never enqueued twice); queued actions start and become running on the next DriveUpdate. Returns the runner itself, so calls are chainable.
this._runner
.QueueAction(actionA)
.QueueAction(actionB);
RemoveAction
public void RemoveAction(int uid)
Removes an action by uid from the running and queued caches; the removed action is marked all done (MarkAllDone) and a removal report is printed.
var action = new SequenceAction("Flow", 1001);
this._runner.QueueAction(action);
// Remove by UID
this._runner.RemoveAction(1001);
Release
public void Release()
Clears all actions (running/queued/done caches).
Important The owner must call Release() on exit (OnDestroy, etc.).