Class XRBaseInteractable
Abstract base class from which all interactable behaviours derive. This class hooks into the interaction system (via XRInteractionManager) and provides base virtual methods for handling hover and selection.
Inherited Members
Namespace: UnityEngine.XR.Interaction.Toolkit
Syntax
[SelectionBase]
[DefaultExecutionOrder(-98)]
public abstract class XRBaseInteractable : MonoBehaviour
Properties
colliders
(Read Only) Colliders to use for interaction with this interactable (if empty, will use any child colliders).
Declaration
public List<Collider> colliders { get; }
Property Value
Type | Description |
---|---|
List<Collider> |
customReticle
The reticle that will appear at the end of the line when it is valid.
Declaration
public GameObject customReticle { get; set; }
Property Value
Type | Description |
---|---|
GameObject |
hoveringInteractors
(Read Only) The list of interactors that are hovering on this interactable.
Declaration
public List<XRBaseInteractor> hoveringInteractors { get; }
Property Value
Type | Description |
---|---|
List<XRBaseInteractor> |
interactionLayerMask
Only interactors with this Layer Mask will interact with this interactable.
Declaration
public LayerMask interactionLayerMask { get; set; }
Property Value
Type | Description |
---|---|
LayerMask |
interactionManager
Manager to handle all interaction management (will find one if empty).
Declaration
public XRInteractionManager interactionManager { get; set; }
Property Value
Type | Description |
---|---|
XRInteractionManager |
isHovered
(Read Only) Indicates whether this interactable is currently being hovered.
Declaration
public bool isHovered { get; }
Property Value
Type | Description |
---|---|
Boolean |
isSelected
(Read Only) Indicates whether this interactable is currently being selected.
Declaration
public bool isSelected { get; }
Property Value
Type | Description |
---|---|
Boolean |
onActivate
Called when an Interactor activates this selected Interactable.
Declaration
public XRInteractableEvent onActivate { get; set; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onDeactivate
Called when an Interactor deactivates this selected Interactable.
Declaration
public XRInteractableEvent onDeactivate { get; set; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onFirstHoverEnter
Declaration
[Obsolete("onFirstHoverEnter has been deprecated. Use onFirstHoverEntered instead. (UnityUpgradable) -> onFirstHoverEntered")]
public XRInteractableEvent onFirstHoverEnter { get; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onFirstHoverEntered
Called only when the first interactor begins hovering over this interactable.
Declaration
public XRInteractableEvent onFirstHoverEntered { get; set; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onHoverEnter
Declaration
[Obsolete("onHoverEnter has been deprecated. Use onHoverEntered instead. (UnityUpgradable) -> onHoverEntered")]
public XRInteractableEvent onHoverEnter { get; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onHoverEntered
Called every time when an interactor begins hovering over this interactable.
Declaration
public XRInteractableEvent onHoverEntered { get; set; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onHoverExit
Declaration
[Obsolete("onHoverExit has been deprecated. Use onHoverExited instead. (UnityUpgradable) -> onHoverExited")]
public XRInteractableEvent onHoverExit { get; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onHoverExited
Called every time when an interactor stops hovering over this interactable.
Declaration
public XRInteractableEvent onHoverExited { get; set; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onLastHoverExit
Declaration
[Obsolete("onLastHoverExit has been deprecated. Use onLastHoverExited instead. (UnityUpgradable) -> onLastHoverExited")]
public XRInteractableEvent onLastHoverExit { get; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onLastHoverExited
Called only when the last interactor stops hovering over this interactable.
Declaration
public XRInteractableEvent onLastHoverExited { get; set; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onSelectCancel
Declaration
[Obsolete("onSelectCancel has been deprecated. Use onSelectCanceled instead. (UnityUpgradable) -> onSelectCanceled")]
public XRInteractableEvent onSelectCancel { get; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onSelectCanceled
Called when the interactor selecting this interactable is disabled or destroyed.
Declaration
public XRInteractableEvent onSelectCanceled { get; set; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onSelectEnter
Declaration
[Obsolete("onSelectEnter has been deprecated. Use onSelectEntered instead. (UnityUpgradable) -> onSelectEntered")]
public XRInteractableEvent onSelectEnter { get; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onSelectEntered
Called when an interactor begins selecting this interactable.
Declaration
public XRInteractableEvent onSelectEntered { get; set; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onSelectExit
Declaration
[Obsolete("onSelectExit has been deprecated. Use onSelectExited instead. (UnityUpgradable) -> onSelectExited")]
public XRInteractableEvent onSelectExit { get; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onSelectExited
Called when an interactor stops selecting this interactable.
Declaration
public XRInteractableEvent onSelectExited { get; set; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
Methods
AttachCustomReticle(XRBaseInteractor)
Declaration
public virtual void AttachCustomReticle(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor |
Awake()
Declaration
protected virtual void Awake()
GetDistanceSqrToInteractor(XRBaseInteractor)
Calculates distance squared to interactor (based on colliders).
Declaration
public float GetDistanceSqrToInteractor(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor to calculate distance against. |
Returns
Type | Description |
---|---|
Single | Returns the minimum distance between the interactor and this interactable's colliders. |
IsHoverableBy(XRBaseInteractor)
Determines if this interactable can be hovered by a given interactor.
Declaration
public virtual bool IsHoverableBy(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor to check for a valid hover state with. |
Returns
Type | Description |
---|---|
Boolean | Returns true if hovering is valid this frame. Returns false if not. |
IsSelectableBy(XRBaseInteractor)
Determines if this interactable can be selected by a given interactor.
Declaration
public virtual bool IsSelectableBy(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor to check for a valid selection with. |
Returns
Type | Description |
---|---|
Boolean | Returns true if selection is valid this frame. Returns false if not. |
OnActivate(XRBaseInteractor)
This method is called by the interaction manager when the interactor sends an activation event down to an interactable.
Declaration
protected virtual void OnActivate(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor that is sending the activation event. |
OnDeactivate(XRBaseInteractor)
Declaration
protected virtual void OnDeactivate(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor |
OnDestroy()
Declaration
protected virtual void OnDestroy()
OnHoverEntered(XRBaseInteractor)
This method is called by the interaction manager when the interactor first initiates hovering over an interactable.
Declaration
protected virtual void OnHoverEntered(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor that is initiating the hover. |
See Also
OnHoverEntering(XRBaseInteractor)
This method is called by the interaction manager right before the interactor first initiates hovering over an interactable.
Declaration
protected virtual void OnHoverEntering(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor that is initiating the hover. |
See Also
OnHoverExited(XRBaseInteractor)
This method is called by the interaction manager when the interactor ends hovering over an interactable.
Declaration
protected virtual void OnHoverExited(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor that is ending the hover. |
See Also
OnHoverExiting(XRBaseInteractor)
This method is called by the interaction manager right before the interactor ends hovering over an interactable.
Declaration
protected virtual void OnHoverExiting(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor that is ending the hover. |
See Also
OnSelectCanceled(XRBaseInteractor)
This method is called by the interaction manager when the interactor targeting this interactable is disabled or destroyed, or if the interactable is unregistered.
Declaration
protected virtual void OnSelectCanceled(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor that is ending the selection. |
See Also
OnSelectCanceling(XRBaseInteractor)
This method is called by the interaction manager right before the interactor targeting this interactable is disabled or destroyed, or if the interactable is unregistered.
Declaration
protected virtual void OnSelectCanceling(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor that is ending the selection. |
See Also
OnSelectEntered(XRBaseInteractor)
This method is called by the interaction manager when the interactor first initiates selection of an interactable.
Declaration
protected virtual void OnSelectEntered(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor that is initiating the selection. |
See Also
OnSelectEntering(XRBaseInteractor)
This method is called by the interaction manager right before the interactor first initiates selection of an interactable.
Declaration
protected virtual void OnSelectEntering(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor that is initiating the selection. |
See Also
OnSelectExited(XRBaseInteractor)
This method is called by the interaction manager when the interactor ends selection of an interactable.
Declaration
protected virtual void OnSelectExited(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor that is ending the selection. |
See Also
OnSelectExiting(XRBaseInteractor)
This method is called by the interaction manager right before the interactor ends selection of an interactable.
Declaration
protected virtual void OnSelectExiting(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor that is ending the selection. |
See Also
ProcessInteractable(XRInteractionUpdateOrder.UpdatePhase)
This method is called by the interaction manager to update the interactable. Please see the interaction manager documentation for more details on update order.
Declaration
public virtual void ProcessInteractable(XRInteractionUpdateOrder.UpdatePhase updatePhase)
Parameters
Type | Name | Description |
---|---|---|
XRInteractionUpdateOrder.UpdatePhase | updatePhase |
RemoveCustomReticle(XRBaseInteractor)
Declaration
public virtual void RemoveCustomReticle(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor |
Reset()
Declaration
[Conditional("UNITY_EDITOR")]
protected virtual void Reset()