Skip to main content

Class Interactor

The mediator between InteractionView and InteractionModel. Translates UI input events into model state changes, and reflects model state changes back into the UI.

public class Interactor : MonoBehaviour

Inheritance​

Remarks​

This class has two directions of responsibility. Inward: it receives pointer events from InteractionView via the OnViewInput_* methods and forwards them as state-mutation calls on InteractionModel (start, update, finish). Outward: it listens to the model's events (InteractionStarted, InteractionUpdated, InteractionCompleted, InteractionCanceled) and tells InteractionView how to update its display in response. It also runs a periodic proximity scan to keep the model's active interactable current.

Input arrives via OnViewInput_* methods called directly by InteractionView's UI event system, rather than polling Input.GetMouseButton each frame. This means swapping the UI toolkit (e.g., replacing pointer input with gamepad or gaze-based input) only requires changing InteractionView — this class and InteractionModel are unaffected.

Finding the closest visible Interactable involves a camera frustum test and a LINQ sort over all nearby objects, which is moderately expensive to run every frame. The scan is therefore throttled to run at most once per interactCheckInterval seconds, since the active interactable rarely changes faster than that interval. The visual fill update is kept on a per-frame Update so the press-to-interact progress ring stays smooth regardless of the poll rate.

Related components

  • InteractionModel: Owns all interaction state; receives state-mutation calls from this class.
  • InteractionView: Drives input events into this class and receives display instructions in return.

Methods​

OnViewInput_OnPointerDown(int)​

Handles pointer down input from the interactor view and starts interaction.

public void OnViewInput_OnPointerDown(int inputIndex)

Parameters​

NameTypeDescription
inputIndexintThe index of the interaction input.

OnViewInput_OnPointerHold(int)​

Handles pointer hold input from the interactor view and updates interaction.

public void OnViewInput_OnPointerHold(int inputIndex)

Parameters​

NameTypeDescription
inputIndexintThe index of the interaction input.

OnViewInput_OnPointerUp(int)​

Handles pointer up input from the interactor view and finishes interaction.

public void OnViewInput_OnPointerUp(int inputIndex)

Parameters​

NameTypeDescription
inputIndexintThe index of the interaction input.

RemoveInteractable(Interactable)​

Removes the specified interactable from the model's list of interactables.

public void RemoveInteractable(Interactable interactable)

Parameters​

NameTypeDescription
interactableInteractableThe interactable to be removed.

SetInteractable(Interactable)​

Adds the specified interactable to the model's list of interactables.

public void SetInteractable(Interactable interactable)

Parameters​

NameTypeDescription
interactableInteractableThe interactable to be added.
  • Remarks
  • Methods
    • OnViewInput_OnPointerDown(int)
    • OnViewInput_OnPointerHold(int)
    • OnViewInput_OnPointerUp(int)
    • RemoveInteractable(Interactable)
    • SetInteractable(Interactable)