Skip to content

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, IInteractor

Events

ActionExecuted

Fired when an action is successfully executed.

public event Action<ActionExecutedEventArgs> ActionExecuted

ActionSelectionChanged

Fired when the selected action changes.

public event Action<ActionSelectionChangedEventArgs> ActionSelectionChanged

ActionsDiscovered

Fired when actions are discovered on a target.

public event Action<ActionsDiscoveredEventArgs> ActionsDiscovered

InteractionEnded

Fired when the interactor stops focusing on a target.

public event Action<InteractionLifecycleEventArgs> InteractionEnded

InteractionStarted

Fired when the interactor starts focusing on a target.

public event Action<InteractionLifecycleEventArgs> InteractionStarted

ShowActionsDiscovered

Fired when actions should be displayed in the UI.

public event Action<ActionsDiscoveredEventArgs> ShowActionsDiscovered

Methods

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

NameTypeDescription
targetFireSoftworks.Interaction.IInteractable
actionFireSoftworks.Interaction.IInteractableAction
resultFireSoftworks.Interaction.InteractionResult

RaiseActionSelectionChanged(IInteractable, int, IInteractableAction)

Raises the ActionSelectionChanged event.

protected void RaiseActionSelectionChanged(IInteractable target, int index, IInteractableAction action)

Parameters

NameTypeDescription
targetFireSoftworks.Interaction.IInteractable
indexSystem.Int32
actionFireSoftworks.Interaction.IInteractableAction

RaiseActionsDiscovered(IInteractable, IReadOnlyList<IInteractableAction>, InteractionContext)

Raises the ActionsDiscovered event.

protected void RaiseActionsDiscovered(IInteractable target, IReadOnlyList<IInteractableAction> actions, InteractionContext context)

Parameters

NameTypeDescription
targetFireSoftworks.Interaction.IInteractable
actionsSystem.Collections.Generic.IReadOnlyList{FireSoftworks.Interaction.IInteractableAction}
contextFireSoftworks.Interaction.InteractionContext

RaiseInteractionEnded(IInteractable)

Raises the InteractionEnded event.

protected void RaiseInteractionEnded(IInteractable target)

Parameters

NameTypeDescription
targetFireSoftworks.Interaction.IInteractable

RaiseInteractionStarted(IInteractable)

Raises the InteractionStarted event.

protected void RaiseInteractionStarted(IInteractable target)

Parameters

NameTypeDescription
targetFireSoftworks.Interaction.IInteractable

RaiseShowActionsDiscovered(IInteractable, IReadOnlyList<IInteractableAction>, InteractionContext)

Raises the ShowActionsDiscovered event.

protected void RaiseShowActionsDiscovered(IInteractable target, IReadOnlyList<IInteractableAction> actions, InteractionContext context)

Parameters

NameTypeDescription
targetFireSoftworks.Interaction.IInteractable
actionsSystem.Collections.Generic.IReadOnlyList{FireSoftworks.Interaction.IInteractableAction}
contextFireSoftworks.Interaction.InteractionContext

SelectAction(int)

Selects a specific action by index.

public IInteractableAction SelectAction(int actionIndex)

Parameters

NameTypeDescription
actionIndexSystem.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> currentActions

currentContext

Snapshot of the interaction context built when a new target is focused.

protected InteractionContext currentContext

currentTarget

The interactable object currently in focus, or null if none.

protected IInteractable currentTarget

interactToShowActions

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 interactToShowActions

isInteractionModeEnabled

true while the player is in the action-selection phase (after ShowInteractions, before execute/cancel).

protected bool isInteractionModeEnabled

selectedActionIndex

Zero-based index of the currently selected action in . -1 means no selection.

protected int selectedActionIndex

showUnavailableActions

[Header("Interaction Settings")]
[Tooltip("Show unavailable actions in the UI (grayed out). Can be overridden per-action.")]
public bool showUnavailableActions