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.
Namespace: UnityEngine.XR.Interaction.Toolkit
Syntax
public abstract class XRBaseInteractable : MonoBehaviour
Properties
cachedDistanceToInteractor
Gets cached distance to the last interactor.
Declaration
public float cachedDistanceToInteractor { get; }
Property Value
Type | Description |
---|---|
Single |
colliders
Gets colliders to use for interaction with this interactable.
Declaration
public IEnumerable<Collider> colliders { get; }
Property Value
Type | Description |
---|---|
IEnumerable<Collider> |
customReticle
Gets or sets 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
Gets the list of interactors that are hovering on this interactable;
Declaration
public List<XRBaseInteractor> hoveringInteractors { get; }
Property Value
Type | Description |
---|---|
List<XRBaseInteractor> |
interactionLayerMask
Gets or sets the layer mask to use to filter interactors that can interact with this interactable.
Declaration
public LayerMask interactionLayerMask { get; set; }
Property Value
Type | Description |
---|---|
LayerMask |
interactionManager
Gets or sets Interaction Manager.
Declaration
public XRInteractionManager interactionManager { get; set; }
Property Value
Type | Description |
---|---|
XRInteractionManager |
isHovered
Gets whether this interactable is currently being hovered.
Declaration
public bool isHovered { get; }
Property Value
Type | Description |
---|---|
Boolean |
isSelected
Gets whether this interactable is currently being selected.
Declaration
public bool isSelected { get; }
Property Value
Type | Description |
---|---|
Boolean |
onActivate
Gets or sets the event that is called when an Interactor activates this Interactable.
Declaration
public XRInteractableEvent onActivate { get; set; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onDeactivate
Gets or sets the event that is called when an Interactor deactivates this Interactable.
Declaration
public XRInteractableEvent onDeactivate { get; set; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onFirstHoverEnter
Gets or sets the event that is called only when the first interactor begins hovering over this interactable.
Declaration
public XRInteractableEvent onFirstHoverEnter { get; set; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onHoverEnter
Gets or sets the event that is called every time when an interactor begins hovering over this interactable.
Declaration
public XRInteractableEvent onHoverEnter { get; set; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onHoverExit
Gets or sets the event that is called every time when an interactor stops hovering over this interactable.
Declaration
public XRInteractableEvent onHoverExit { get; set; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onLastHoverExit
Gets or sets the event that is called only when the last interactor stops hovering over this interactable.
Declaration
public XRInteractableEvent onLastHoverExit { get; set; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onSelectEnter
Gets or sets the event that is called when an interactor begins selecting this interactable.
Declaration
public XRInteractableEvent onSelectEnter { get; set; }
Property Value
Type | Description |
---|---|
XRInteractableEvent |
onSelectExit
Gets or sets the event that is called when an interactor stops selecting this interactable.
Declaration
public XRInteractableEvent onSelectExit { 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 | 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 | True if hovering is valid this frame, 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 | True if selection is valid this frame, 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 |
OnHoverEnter(XRBaseInteractor)
This method is called by the interaction manager when the interactor first initiates hovering over an interactable.
Declaration
protected virtual void OnHoverEnter(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor that is initiating the hover. |
OnHoverExit(XRBaseInteractor)
This method is called by the interaction manager when the interactor ends hovering over an interactable.
Declaration
protected virtual void OnHoverExit(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor that is ending the hover. |
OnSelectEnter(XRBaseInteractor)
This method is called by the interaction manager when the interactor first initiates selection of an interactable.
Declaration
protected virtual void OnSelectEnter(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor that is initiating the selection. |
OnSelectExit(XRBaseInteractor)
This method is called by the interaction manager when the interactor ends selection of an interactable.
Declaration
protected virtual void OnSelectExit(XRBaseInteractor interactor)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractor | interactor | Interactor that is ending the selection. |
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
protected virtual void Reset()