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> : ScriptableObject, IExecutable<TContext>
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
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.
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.