Skip to content

InteractorBase

Namespace: FireSoftworks.Interaction
Type: Abstract class · MonoBehaviour · partial
Assembly: FireSofworks.InteractionSystem
Implements: IInteractor

Abstract base class for all interactors. Implements the full action management, selection, and event-raising pipeline — leaving only detection logic to subclasses.

public abstract partial class InteractorBase : MonoBehaviour, IInteractor

Inspector fields

FieldTypeDefaultDescription
showUnavailableActionsbooltrueShow unavailable actions in the UI grayed out.
interactToShowActionsboolfalseWhen true, first press shows actions; second press executes the selected one.

UnityEvents (Inspector)

FieldArgs typeFires when
onInteractionStartedInteractionLifecycleEventArgsFocus begins
onActionsDiscoveredActionsDiscoveredEventArgsTarget focused, actions built
onShowActionsDiscoveredActionsDiscoveredEventArgsAction menu should appear
onActionSelectionChangedActionSelectionChangedEventArgsSelected index changes
onActionExecutedActionExecutedEventArgsAction executes
onInteractionEndedInteractionLifecycleEventArgsFocus lost

Protected state

FieldTypeDescription
currentTargetIInteractableThe currently focused interactable. Set by subclass detection logic.
currentActionsList<IInteractableAction>Cached action list for the current target.
selectedActionIndexintIndex of the selected action; -1 = none selected.
currentContextInteractionContextThe interaction context built by the subclass.
isInteractionModeEnabledbooltrue after ShowInteractions() is called.

IInteractor properties

isInteractionAvailable

true when currentTarget != null.

isValidInteractionSelected

true when a target is focused and selectedActionIndex points to a valid action.

SelectedAction

Returns currentActions[selectedActionIndex], or null.


Virtual methods (override in subclasses)

HandleInteraction()

public virtual void HandleInteraction()

Delegates to ShowInteractions() or ExecuteInteraction() based on interactToShowActions and current state.


ShowInteractions()

public virtual void ShowInteractions()

Fires ShowActionsDiscovered, selects the first available action, and sets isInteractionModeEnabled = true.


ExecuteInteraction()

public virtual void ExecuteInteraction()

Validates that SelectedAction.IsAvailable(), calls Execute(), fires ActionExecuted, then calls EndInteraction().


EndInteraction()

public virtual void EndInteraction()

Calls ClearCurrentTarget() which: calls currentTarget.OnFocusExit(), fires InteractionEnded, clears all state.


C# Events

EventDelegate typeFires when
ActionsDiscoveredAction<ActionsDiscoveredEventArgs>New target focused
ShowActionsDiscoveredAction<ActionsDiscoveredEventArgs>Action menu should appear
ActionSelectionChangedAction<ActionSelectionChangedEventArgs>Selection changes
ActionExecutedAction<ActionExecutedEventArgs>Action completes
InteractionStartedAction<InteractionLifecycleEventArgs>Focus begins
InteractionEndedAction<InteractionLifecycleEventArgs>Focus lost

Protected event raisers (for subclasses)

protected void RaiseActionsDiscovered(IInteractable target, IReadOnlyList<IInteractableAction> actions, InteractionContext context);
protected void RaiseShowActionsDiscovered(IInteractable target, IReadOnlyList<IInteractableAction> actions, InteractionContext context);
protected void RaiseActionSelectionChanged(IInteractable target, int index, IInteractableAction action);
protected void RaiseActionExecuted(IInteractable target, IInteractableAction action, InteractionResult result);
protected void RaiseInteractionStarted(IInteractable target);
protected void RaiseInteractionEnded(IInteractable target);

Call these from your subclass after updating currentTarget to notify all subscribers (both C# event listeners and Inspector-wired UnityEvents).