Class GameAction<TContext>
- Namespace
- ElectricDrill.AstraRpgFramework.GameActions
- Assembly
- com.electricdrill.astra-rpg-framework.Runtime.dll
Abstract base class for executable actions that can be configured as ScriptableObject assets. Derive from this class to create reusable, serializable actions that can be assigned in the editor. Uses Unity's Awaitable system for zero-allocation async execution.
public abstract class GameAction<TContext> : GameActionBase, IExecutable<TContext>, ITaggable
Type Parameters
TContextThe type of context object passed to the execution method.
- Inheritance
-
objectGameAction<TContext>
- Implements
-
IExecutable<TContext>
- Derived
Properties
DisplayName
A human-readable name for this action, shown in editors and debugging. Override to provide a descriptive name for your action.
public virtual string DisplayName { get; }
Property Value
- string
Tags
The tags associated with this object.
public GameTagSet Tags { get; }
Property Value
Methods
ExecuteAsync(TContext, CancellationToken)
Executes the action asynchronously with the provided context. Override this method to implement your action logic.
public abstract Awaitable ExecuteAsync(TContext context, CancellationToken cancellationToken = default)
Parameters
contextTContextThe context object containing information needed for execution.
cancellationTokenCancellationTokenToken to cancel the operation. MonoBehaviour owners can use their "destroyCancellationToken" to automatically cancel when destroyed.
Returns
- Awaitable
An Awaitable that completes when the action finishes.
ExecuteAsyncForUnityEvent(TContext)
Wrapper to execute this action asynchronously for UnityEvent calls. Runs in fire-and-forget manner. Exceptions are caught and logged to avoid unhandled exceptions in UnityEvent calls.
public void ExecuteAsyncForUnityEvent(TContext context)
Parameters
contextTContextThe context to pass to the action.
ExecuteWithOwnerAsync(TContext, MonoBehaviour, CancellationToken)
Owner-aware execution path. The runtimeOwner identifies the
MonoBehaviour (typically a listener or runner) whose entity is the logical owner of this
action invocation. Wrapper actions must override this to forward the owner to children.
The default implementation ignores the owner and delegates to ExecuteAsync(TContext, CancellationToken), so leaf actions that do not need owner information require no changes.
public virtual Awaitable ExecuteWithOwnerAsync(TContext context, MonoBehaviour runtimeOwner, CancellationToken cancellationToken = default)
Parameters
contextTContextThe context object containing information needed for execution.
runtimeOwnerMonoBehaviourThe MonoBehaviour that owns this action invocation at runtime. Used by conditional actions to populate
EvaluationContext.Holder.cancellationTokenCancellationTokenToken to cancel the operation.
Returns
- Awaitable
An Awaitable that completes when the action finishes.
OnOperationCanceled()
protected virtual void OnOperationCanceled()
RunFireAndForget(TContext, MonoBehaviour)
Executes this action fire-and-forget with automatic lifecycle management. The action will be canceled if the owner GameObject is destroyed. Multiple actions can run concurrently on the same owner.
public void RunFireAndForget(TContext context, MonoBehaviour owner)
Parameters
contextTContextThe context to pass to the action.
ownerMonoBehaviourThe MonoBehaviour that owns this action's lifecycle. A GameActionRunner will be automatically added to its GameObject if needed.