Class XRInteractionManager
The Interaction Manager acts as an intermediary between Interactors and Interactables. It is possible to have multiple Interaction Managers, each with their own valid set of Interactors and Interactables. Upon being enabled, both Interactors and Interactables register themselves with a valid Interaction Manager (if a specific one has not already been assigned in the inspector). The loaded scenes must have at least one Interaction Manager for Interactors and Interactables to be able to communicate.
Namespace: UnityEngine.XR.Interaction.Toolkit
Syntax
public class XRInteractionManager : MonoBehaviour
Remarks
Many of the methods on the abstract base classes of Interactors and Interactables are designed to be internal such that they can be called by this Interaction Manager rather than being called directly in order to maintain consistency between both targets of an interaction event.
Methods
CancelInteractableHover(XRBaseInteractable)
Automatically called when an Interactable is unregistered to cancel the hover state of the Interactable if necessary.
Declaration
public virtual void CancelInteractableHover(XRBaseInteractable interactable)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractable | interactable | The Interactable to potentially exit its hover state due to cancellation. |
CancelInteractableSelection(XRBaseInteractable)
Automatically called when an Interactable is unregistered to cancel the selection of the Interactable if necessary.
Declaration
public virtual void CancelInteractableSelection(XRBaseInteractable interactable)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractable | interactable | The Interactable to potentially exit its selection state due to cancellation. |
CancelInteractorHover(XRBaseInteractor)
Automatically called when an Interactor is unregistered to cancel the hover state of the Interactor if necessary.
Declaration
public virtual void CancelInteractorHover(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | The Interactor to potentially exit its hover state due to cancellation. |
CancelInteractorSelection(XRBaseInteractor)
Automatically called when an Interactor is unregistered to cancel the selection of the Interactor if necessary.
Declaration
public virtual void CancelInteractorSelection(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | The Interactor to potentially exit its selection state due to cancellation. |
ClearInteractorHover(XRBaseInteractor, List<XRBaseInteractable>)
Automatically called each frame during Update to clear the hover state of the Interactor if necessary due to current conditions.
Declaration
public virtual void ClearInteractorHover(XRBaseInteractor interactor, List<XRBaseInteractable> validTargets)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | The Interactor to potentially exit its hover state. |
List<XRBaseInteractable> | validTargets | The list of interactables that this Interactor could possibly interact with this frame. |
ClearInteractorSelection(XRBaseInteractor)
Automatically called each frame during Update to clear the selection of the Interactor if necessary due to current conditions.
Declaration
public virtual void ClearInteractorSelection(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | The Interactor to potentially exit its selection state. |
FixedUpdate()
See
Declaration
protected virtual void FixedUpdate()
ForceSelect(XRBaseInteractor, XRBaseInteractable)
Force selects an Interactable.
Declaration
public void ForceSelect(XRBaseInteractor interactor, XRBaseInteractable interactable)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | The Interactor that will force select the Interactable. |
XRBaseInteractable | interactable | The Interactable to be forced selected. |
GetColliderToInteractableMap(ref Dictionary<Collider, XRBaseInteractable>)
Gets the dictionary that has all the registered colliders and their associated Interactable.
Declaration
public void GetColliderToInteractableMap(ref Dictionary<Collider, XRBaseInteractable> map)
Parameters
Type | Name | Description |
---|---|---|
Dictionary<Collider, XRBaseInteractable> | map | When this method returns, contains the dictionary that has all the registered colliders and their associated Interactable. |
GetInteractableForCollider(Collider)
Gets the Interactable a specific collider is attached to.
Declaration
public XRBaseInteractable GetInteractableForCollider(Collider interactableCollider)
Parameters
Type | Name | Description |
---|---|---|
Collider | interactableCollider | The collider of the Interactable to retrieve. |
Returns
Type | Description |
---|---|
XRBaseInteractable | The Interactable that the collider is attached to. Otherwise returns null if no such Interactable exists. |
GetRegisteredInteractables(List<XRBaseInteractable>)
Return all registered Interactables into List results
.
Declaration
public void GetRegisteredInteractables(List<XRBaseInteractable> results)
Parameters
Type | Name | Description |
---|---|---|
List<XRBaseInteractable> | results | List to receive registered Interactables. |
Remarks
This method populates the list with the registered Interactables at the time the method is called. It is not a live view, meaning Interactables registered or unregistered afterward will not be reflected in the results of this method.
See Also
GetRegisteredInteractors(List<XRBaseInteractor>)
Return all registered Interactors into List results
.
Declaration
public void GetRegisteredInteractors(List<XRBaseInteractor> results)
Parameters
Type | Name | Description |
---|---|---|
List<XRBaseInteractor> | results | List to receive registered Interactors. |
Remarks
This method populates the list with the registered Interactors at the time the method is called. It is not a live view, meaning Interactors registered or unregistered afterward will not be reflected in the results of this method.
See Also
GetValidTargets(XRBaseInteractor, List<XRBaseInteractable>)
For the provided interactor
, return a list of the valid Interactables that can be hovered over or selected.
Declaration
public List<XRBaseInteractable> GetValidTargets(XRBaseInteractor interactor, List<XRBaseInteractable> validTargets)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | The Interactor whose valid targets we want to find. |
List<XRBaseInteractable> | validTargets | List to be filled with valid targets of the Interactor. |
Returns
Type | Description |
---|---|
List<XRBaseInteractable> | The list of valid targets of the Interactor. |
See Also
HoverCancel(XRBaseInteractor, XRBaseInteractable)
Initiates ending hovering of an Interactable by an Interactor due to cancellation, such as from either being unregistered due to being disabled or destroyed.
Declaration
public virtual void HoverCancel(XRBaseInteractor interactor, XRBaseInteractable interactable)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | The Interactor that is no longer hovering. |
XRBaseInteractable | interactable | The Interactable that is no longer being hovered over. |
HoverEnter(XRBaseInteractor, XRBaseInteractable)
Initiates hovering of an Interactable by an Interactor.
Declaration
public virtual void HoverEnter(XRBaseInteractor interactor, XRBaseInteractable interactable)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | The Interactor that is hovering. |
XRBaseInteractable | interactable | The Interactable being hovered over. |
HoverEnter(XRBaseInteractor, XRBaseInteractable, HoverEnterEventArgs)
Initiates hovering of an Interactable by an Interactor, passing the given args
.
Declaration
protected virtual void HoverEnter(XRBaseInteractor interactor, XRBaseInteractable interactable, HoverEnterEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | The Interactor that is hovering. |
XRBaseInteractable | interactable | The Interactable being hovered over. |
HoverEnterEventArgs | args | Event data containing the Interactor and Interactable involved in the event. |
HoverExit(XRBaseInteractor, XRBaseInteractable)
Initiates ending hovering of an Interactable by an Interactor.
Declaration
public virtual void HoverExit(XRBaseInteractor interactor, XRBaseInteractable interactable)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | The Interactor that is no longer hovering. |
XRBaseInteractable | interactable | The Interactable that is no longer being hovered over. |
HoverExit(XRBaseInteractor, XRBaseInteractable, HoverExitEventArgs)
Initiates ending hovering of an Interactable by an Interactor, passing the given args
.
Declaration
protected virtual void HoverExit(XRBaseInteractor interactor, XRBaseInteractable interactable, HoverExitEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | The Interactor that is no longer hovering. |
XRBaseInteractable | interactable | The Interactable that is no longer being hovered over. |
HoverExitEventArgs | args | Event data containing the Interactor and Interactable involved in the event. |
InteractorHoverValidTargets(XRBaseInteractor, List<XRBaseInteractable>)
Automatically called each frame during Update to enter the hover state of the Interactor if necessary due to current conditions.
Declaration
protected virtual void InteractorHoverValidTargets(XRBaseInteractor interactor, List<XRBaseInteractable> validTargets)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | The Interactor to potentially enter its hover state. |
List<XRBaseInteractable> | validTargets | The list of interactables that this Interactor could possibly interact with this frame. |
InteractorSelectValidTargets(XRBaseInteractor, List<XRBaseInteractable>)
Automatically called each frame during Update to enter the selection state of the Interactor if necessary due to current conditions.
Declaration
protected virtual void InteractorSelectValidTargets(XRBaseInteractor interactor, List<XRBaseInteractable> validTargets)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | The Interactor to potentially enter its selection state. |
List<XRBaseInteractable> | validTargets | The list of interactables that this Interactor could possibly interact with this frame. |
IsRegistered(XRBaseInteractable)
Checks whether the interactable
is registered with this Interaction Manager.
Declaration
public bool IsRegistered(XRBaseInteractable interactable)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractable | interactable | The Interactable to check. |
Returns
Type | Description |
---|---|
Boolean |
See Also
IsRegistered(XRBaseInteractor)
Checks whether the interactor
is registered with this Interaction Manager.
Declaration
public bool IsRegistered(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | The Interactor to check. |
Returns
Type | Description |
---|---|
Boolean |
See Also
LateUpdate()
See
Declaration
protected virtual void LateUpdate()
OnBeforeRender()
Delegate method used to register for "Just Before Render" input updates for VR devices.
Declaration
protected virtual void OnBeforeRender()
OnDisable()
See
Declaration
protected virtual void OnDisable()
OnEnable()
See
Declaration
protected virtual void OnEnable()
OnRegistered(InteractableRegisteredEventArgs)
Automatically called when an Interactable is registered with this Interaction Manager.
Notifies the Interactable, passing the given args
.
Declaration
protected virtual void OnRegistered(InteractableRegisteredEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
InteractableRegisteredEventArgs | args | Event data containing the registered Interactable. |
Remarks
args
is only valid during this method call, do not hold a reference to it.
See Also
OnRegistered(InteractorRegisteredEventArgs)
Automatically called when an Interactor is registered with this Interaction Manager.
Notifies the Interactor, passing the given args
.
Declaration
protected virtual void OnRegistered(InteractorRegisteredEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
InteractorRegisteredEventArgs | args | Event data containing the registered Interactor. |
Remarks
args
is only valid during this method call, do not hold a reference to it.
See Also
OnUnregistered(InteractableUnregisteredEventArgs)
Automatically called when an Interactable is unregistered from this Interaction Manager.
Notifies the Interactable, passing the given args
.
Declaration
protected virtual void OnUnregistered(InteractableUnregisteredEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
InteractableUnregisteredEventArgs | args | Event data containing the unregistered Interactable. |
Remarks
args
is only valid during this method call, do not hold a reference to it.
See Also
OnUnregistered(InteractorUnregisteredEventArgs)
Automatically called when an Interactor is unregistered from this Interaction Manager.
Notifies the Interactor, passing the given args
.
Declaration
protected virtual void OnUnregistered(InteractorUnregisteredEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
InteractorUnregisteredEventArgs | args | Event data containing the unregistered Interactor. |
Remarks
args
is only valid during this method call, do not hold a reference to it.
See Also
ProcessInteractables(XRInteractionUpdateOrder.UpdatePhase)
Process all interactables in a scene.
Declaration
protected virtual void ProcessInteractables(XRInteractionUpdateOrder.UpdatePhase updatePhase)
Parameters
Type | Name | Description |
---|---|---|
XRInteractionUpdateOrder.UpdatePhase | updatePhase | The update phase. |
ProcessInteractors(XRInteractionUpdateOrder.UpdatePhase)
Process all interactors in a scene.
Declaration
protected virtual void ProcessInteractors(XRInteractionUpdateOrder.UpdatePhase updatePhase)
Parameters
Type | Name | Description |
---|---|---|
XRInteractionUpdateOrder.UpdatePhase | updatePhase | The update phase. |
RegisterInteractable(XRBaseInteractable)
Register a new Interactable to be processed.
Declaration
public virtual void RegisterInteractable(XRBaseInteractable interactable)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractable | interactable | The Interactable to be registered. |
RegisterInteractor(XRBaseInteractor)
Register a new Interactor to be processed.
Declaration
public virtual void RegisterInteractor(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | The Interactor to be registered. |
SelectCancel(XRBaseInteractor, XRBaseInteractable)
Initiates ending selection of an Interactable by an Interactor due to cancellation, such as from either being unregistered due to being disabled or destroyed.
Declaration
public virtual void SelectCancel(XRBaseInteractor interactor, XRBaseInteractable interactable)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | The Interactor that is no longer selecting. |
XRBaseInteractable | interactable | The Interactable that is no longer being selected. |
SelectEnter(XRBaseInteractor, XRBaseInteractable)
Initiates selection of an Interactable by an Interactor. This method may cause the Interactable to first exit being selected.
Declaration
public virtual void SelectEnter(XRBaseInteractor interactor, XRBaseInteractable interactable)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | The Interactor that is selecting. |
XRBaseInteractable | interactable | The Interactable being selected. |
Remarks
This attempt will be ignored if the Interactor requires exclusive selection of an Interactable and that Interactable is already selected by another Interactor.
SelectEnter(XRBaseInteractor, XRBaseInteractable, SelectEnterEventArgs)
Initiates selection of an Interactable by an Interactor, passing the given args
.
Declaration
protected virtual void SelectEnter(XRBaseInteractor interactor, XRBaseInteractable interactable, SelectEnterEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | The Interactor that is selecting. |
XRBaseInteractable | interactable | The Interactable being selected. |
SelectEnterEventArgs | args | Event data containing the Interactor and Interactable involved in the event. |
SelectExit(XRBaseInteractor, XRBaseInteractable)
Initiates ending selection of an Interactable by an Interactor.
Declaration
public virtual void SelectExit(XRBaseInteractor interactor, XRBaseInteractable interactable)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | The Interactor that is no longer selecting. |
XRBaseInteractable | interactable | The Interactable that is no longer being selected. |
SelectExit(XRBaseInteractor, XRBaseInteractable, SelectExitEventArgs)
Initiates ending selection of an Interactable by an Interactor, passing the given args
.
Declaration
protected virtual void SelectExit(XRBaseInteractor interactor, XRBaseInteractable interactable, SelectExitEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | The Interactor that is no longer selecting. |
XRBaseInteractable | interactable | The Interactable that is no longer being selected. |
SelectExitEventArgs | args | Event data containing the Interactor and Interactable involved in the event. |
TryGetInteractableForCollider(Collider)
Gets the Interactable a specific collider is attached to.
Declaration
public XRBaseInteractable TryGetInteractableForCollider(Collider interactableCollider)
Parameters
Type | Name | Description |
---|---|---|
Collider | interactableCollider | The collider of the Interactable to retrieve. |
Returns
Type | Description |
---|---|
XRBaseInteractable | The Interactable that the collider is attached to. Otherwise returns null if no such Interactable exists. |
UnregisterInteractable(XRBaseInteractable)
Unregister an Interactable so it is no longer processed.
Declaration
public virtual void UnregisterInteractable(XRBaseInteractable interactable)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractable | interactable | The Interactable to be unregistered. |
UnregisterInteractor(XRBaseInteractor)
Unregister an Interactor so it is no longer processed.
Declaration
public virtual void UnregisterInteractor(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | The Interactor to be unregistered. |
Update()
See
Declaration
protected virtual void Update()
Events
interactableRegistered
Calls the methods in its invocation list when an XRBaseInteractable is registered.
Declaration
public event Action<InteractableRegisteredEventArgs> interactableRegistered
Event Type
Type | Description |
---|---|
Action<InteractableRegisteredEventArgs> |
Remarks
The InteractableRegisteredEventArgs passed to each listener is only valid while the event is invoked, do not hold a reference to it.
See Also
interactableUnregistered
Calls the methods in its invocation list when an XRBaseInteractable is unregistered.
Declaration
public event Action<InteractableUnregisteredEventArgs> interactableUnregistered
Event Type
Type | Description |
---|---|
Action<InteractableUnregisteredEventArgs> |
Remarks
The InteractableUnregisteredEventArgs passed to each listener is only valid while the event is invoked, do not hold a reference to it.
See Also
interactorRegistered
Calls the methods in its invocation list when an XRBaseInteractor is registered.
Declaration
public event Action<InteractorRegisteredEventArgs> interactorRegistered
Event Type
Type | Description |
---|---|
Action<InteractorRegisteredEventArgs> |
Remarks
The InteractorRegisteredEventArgs passed to each listener is only valid while the event is invoked, do not hold a reference to it.
See Also
interactorUnregistered
Calls the methods in its invocation list when an XRBaseInteractor is unregistered.
Declaration
public event Action<InteractorUnregisteredEventArgs> interactorUnregistered
Event Type
Type | Description |
---|---|
Action<InteractorUnregisteredEventArgs> |
Remarks
The InteractorUnregisteredEventArgs passed to each listener is only valid while the event is invoked, do not hold a reference to it.