Module Intro
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
RunActionor enqueue them withQueueAction, and have the owner (a MonoBehaviourUpdate, etc.) callDriveUpdate(dt)to pump updates. - ActionBase: The abstract base class of all actions. Override
OnStart/OnUpdate/OnDoneto implement custom actions, and control completion withSetDurationandMarkAsDone. - 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
- Create an
ActionRunner(name it for log identification). - Compose actions (default actions or custom actions).
- Start with
RunAction(or append withQueueAction). - Have the owner call
DriveUpdate(Time.deltaTime)inUpdateto drive the run. - 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)
- Use UniTask v2.5.0 or higher, Add https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask to Package Manager
- Use OxGKit.LoggingSystem, Add https://github.com/michael811125/OxGKit.git?path=Assets/OxGKit/LoggingSystem/Scripts to Package Manager
Samples (Package Manager -> Samples)
- AI Agent Skills (see AI Agent Skills)
- ActionSystem Demo
Module API
- Runtime
- ActionRunner (using OxGKit.ActionSystem)
- ActionBase (using OxGKit.ActionSystem)
- Default Actions (using OxGKit.ActionSystem)
Demo
ActionSystem Demo