InteractorBase
Namespace: FireSoftworks.Interaction
Assembly: FireSoftworks.Interaction
Type: Class
Abstract base class for all interactors. Implements the core logic for action management, selection, and event raising, while leaving the detection logic to subclasses.
public abstract class InteractorBase : MonoBehaviour, IInteractorEvents
ActionExecuted
Fired when an action is successfully executed.
public event Action<ActionExecutedEventArgs> ActionExecutedActionSelectionChanged
Fired when the selected action changes.
public event Action<ActionSelectionChangedEventArgs> ActionSelectionChangedActionsDiscovered
Fired when actions are discovered on a target.
public event Action<ActionsDiscoveredEventArgs> ActionsDiscoveredInteractionEnded
Fired when the interactor stops focusing on a target.
public event Action<InteractionLifecycleEventArgs> InteractionEndedInteractionStarted
Fired when the interactor starts focusing on a target.
public event Action<InteractionLifecycleEventArgs> InteractionStartedShowActionsDiscovered
Fired when actions should be displayed in the UI.
public event Action<ActionsDiscoveredEventArgs> ShowActionsDiscoveredMethods
ClearCurrentTarget()
Clears the current target, fires , resets all selection state, and calls on the previous target.
protected virtual void ClearCurrentTarget()EndInteraction()
Cancels the current interaction and clears the target.
public virtual void EndInteraction()ExecuteInteraction()
Executes the currently selected action.
public virtual void ExecuteInteraction()GetVisibleActions()
Returns the list of actions that should be visible in the UI.
public List<IInteractableAction> GetVisibleActions()HandleInteraction()
Handles interaction input, either showing actions or executing the selected one.
public virtual void HandleInteraction()IsInteracting()
Checks if the interactor is currently in interaction mode or has a target.
public virtual bool IsInteracting()RaiseActionExecuted(IInteractable, IInteractableAction, InteractionResult)
Raises the ActionExecuted event.
protected void RaiseActionExecuted(IInteractable target, IInteractableAction action, InteractionResult result)Parameters
| Name | Type | Description |
|---|---|---|
target | FireSoftworks.Interaction.IInteractable | |
action | FireSoftworks.Interaction.IInteractableAction | |
result | FireSoftworks.Interaction.InteractionResult |
RaiseActionSelectionChanged(IInteractable, int, IInteractableAction)
Raises the ActionSelectionChanged event.
protected void RaiseActionSelectionChanged(IInteractable target, int index, IInteractableAction action)Parameters
| Name | Type | Description |
|---|---|---|
target | FireSoftworks.Interaction.IInteractable | |
index | System.Int32 | |
action | FireSoftworks.Interaction.IInteractableAction |
RaiseActionsDiscovered(IInteractable, IReadOnlyList<IInteractableAction>, InteractionContext)
Raises the ActionsDiscovered event.
protected void RaiseActionsDiscovered(IInteractable target, IReadOnlyList<IInteractableAction> actions, InteractionContext context)Parameters
| Name | Type | Description |
|---|---|---|
target | FireSoftworks.Interaction.IInteractable | |
actions | System.Collections.Generic.IReadOnlyList{FireSoftworks.Interaction.IInteractableAction} | |
context | FireSoftworks.Interaction.InteractionContext |
RaiseInteractionEnded(IInteractable)
Raises the InteractionEnded event.
protected void RaiseInteractionEnded(IInteractable target)Parameters
| Name | Type | Description |
|---|---|---|
target | FireSoftworks.Interaction.IInteractable |
RaiseInteractionStarted(IInteractable)
Raises the InteractionStarted event.
protected void RaiseInteractionStarted(IInteractable target)Parameters
| Name | Type | Description |
|---|---|---|
target | FireSoftworks.Interaction.IInteractable |
RaiseShowActionsDiscovered(IInteractable, IReadOnlyList<IInteractableAction>, InteractionContext)
Raises the ShowActionsDiscovered event.
protected void RaiseShowActionsDiscovered(IInteractable target, IReadOnlyList<IInteractableAction> actions, InteractionContext context)Parameters
| Name | Type | Description |
|---|---|---|
target | FireSoftworks.Interaction.IInteractable | |
actions | System.Collections.Generic.IReadOnlyList{FireSoftworks.Interaction.IInteractableAction} | |
context | FireSoftworks.Interaction.InteractionContext |
SelectAction(int)
Selects a specific action by index.
public IInteractableAction SelectAction(int actionIndex)Parameters
| Name | Type | Description |
|---|---|---|
actionIndex | System.Int32 |
SelectNextAction()
Cycles to the next available action.
public IInteractableAction SelectNextAction()SelectPreviousAction()
Cycles to the previous available action.
public IInteractableAction SelectPreviousAction()ShowInteractions()
Enters interaction mode and shows the available actions.
public virtual void ShowInteractions()Propertys
SelectedAction
Gets the currently selected action, or null if none is selected.
public IInteractableAction SelectedAction { get; }isInteractionAvailable
Indicates whether there is a currently focused interactable target.
public bool isInteractionAvailable { get; }isValidInteractionSelected
Indicates whether there is a valid selected action that can be executed.
public bool isValidInteractionSelected { get; }Fields
currentActions
All actions retrieved from (available and unavailable).
protected List<IInteractableAction> currentActionscurrentContext
Snapshot of the interaction context built when a new target is focused.
protected InteractionContext currentContextcurrentTarget
The interactable object currently in focus, or null if none.
protected IInteractable currentTargetinteractToShowActions
If true, the first interaction input will show the available actions without executing.
[Tooltip("If true, the first interaction input will show actions. Subsequent input executes.")]public bool interactToShowActionsisInteractionModeEnabled
true while the player is in the action-selection phase (after ShowInteractions, before execute/cancel).
protected bool isInteractionModeEnabledselectedActionIndex
Zero-based index of the currently selected action in . -1 means no selection.
protected int selectedActionIndexshowUnavailableActions
[Header("Interaction Settings")][Tooltip("Show unavailable actions in the UI (grayed out). Can be overridden per-action.")]public bool showUnavailableActions