Skip to main content

Module Intro

Important Attention Reminder

Coding Style wiki


Basic Instructions

An action-sequence system that lets you define your own Actions and freely compose them into run groups. The default Actions are SequenceAction, ParallelAction, ParallelDelayAction, DelayAction, DelegateAction. It can also be used to stitch together timed animation flows.

  • Version: v1.0.3 (com.michaelo.oxgkit.actionsystem)
  • Namespace: OxGKit.ActionSystem

Attention This module depends on UniTask and OxGKit.LoggingSystem (install them yourself, see Installation). Done and removed action reports are printed through the LoggingSystem logger OxGKit.ActionSystem.Logger.


Application Description

Core Concepts

  • ActionRunner: The action runner. Start actions with RunAction or enqueue them with QueueAction, and have the owner (a MonoBehaviour Update, etc.) call DriveUpdate(dt) to pump updates.
  • ActionBase: The abstract base class of all actions. Override OnStart / OnUpdate / OnDone to implement custom actions, and control completion with SetDuration and MarkAsDone.
  • Default Actions: The built-in actions - SequenceAction (sequence), ParallelAction (parallel), ParallelDelayAction (staggered parallel), DelayAction (delay), DelegateAction (delegate callback) - all of which can be nested and composed with each other.

Run Flow

  1. Create an ActionRunner (name it for log identification).
  2. Compose actions (default actions or custom actions).
  3. Start with RunAction (or append with QueueAction).
  4. Have the owner call DriveUpdate(Time.deltaTime) in Update to drive the run.
  5. Call Release() when the owner exits.

Important A runner must be driven by a single owner through DriveUpdate; without a driver, actions do not advance.

Attention RunAction resets the runner before starting the action (replace behavior); use QueueAction to append actions instead.

Script Template

  • Implement a custom Action via Right-Click Create/OxGKit/Action System/Template Action.cs.

Reminder If a custom action uses SetDuration(-1) (end by condition), it must call MarkAsDone() itself to finish.


Simple Usage

Driving an ActionRunner

using OxGKit.ActionSystem;
using UnityEngine;

public class ActionDemo : MonoBehaviour
{
private ActionRunner _actionRunner;

private void Awake()
{
this._actionRunner = new ActionRunner("ActionRunner");
}

private void Update()
{
// Call by Main MonoBehaviour (Main Program)
this._actionRunner?.DriveUpdate(Time.deltaTime);
}

private void OnDestroy()
{
// Release the runner on exit
this._actionRunner?.Release();
}
}

Composing a Sequence (SequenceAction)

var seqAction = new SequenceAction("Colorful Sequence Callback Actions");

// Add actions in order (delayTime greater than 0 delays before invoking the callback)
seqAction.AddAction(DelegateAction.CreateDelegateAction(() => Debug.Log("[Seq] Hello Red"), 0f));
seqAction.AddAction(DelegateAction.CreateDelegateAction(() => Debug.Log("[Seq] Hello Yellow"), 1f));
seqAction.AddAction(DelegateAction.CreateDelegateAction(() => Debug.Log("[Seq] Hello Green"), 2f));

// Use ActionRunner to start sequence actions
this._actionRunner.RunAction(seqAction);

Composing a Parallel Group (ParallelAction)

var parAction = new ParallelAction("Colorful Parallel Callback Actions");

// Add actions (run simultaneously)
parAction.AddAction(DelegateAction.CreateDelegateAction(() => Debug.Log("[Par] Hello Red")));
parAction.AddAction(DelegateAction.CreateDelegateAction(() => Debug.Log("[Par] Hello Yellow")));
parAction.AddAction(DelegateAction.CreateDelegateAction(() => Debug.Log("[Par] Hello Green")));

// Use ActionRunner to start parallel actions
this._actionRunner.RunAction(parAction);

Implementing a Custom Action

using OxGKit.ActionSystem;

public class NewTplAction : ActionBase
{
#region Default Constructor
public NewTplAction()
{
this.name = nameof(NewTplAction);
}

public NewTplAction(int uid) : this()
{
this.uid = uid;
}
#endregion

protected override void OnStart()
{
// Set -1 is end by condition or duration time (-1 = have to MarkAsDone manually)
this.SetDuration(-1);

// Do somethings...

// And then if SetDuration(-1), the end must invoke MarkAsDone
this.MarkAsDone();
}
}

[See Example]


Installation

Install via git URL
Add https://github.com/michael811125/OxGKit.git?path=Assets/OxGKit/ActionSystem/Scripts to Package Manager

Third-party libraries (install yourself)

Samples (Package Manager -> Samples)


Module API


Demo

ActionSystem Demo