Class XRSocketInteractor
Interactor used for holding interactables via a socket. This component is not designed to be attached to a controller (thus does not derive from XRBaseControllerInteractor) and instead will always attempt to select an interactable that it is hovering over.
Inherited Members
Namespace: UnityEngine.XR.Interaction.Toolkit
Syntax
[DisallowMultipleComponent]
[AddComponentMenu("XR/XR Socket Interactor", 11)]
[HelpURL("https://docs.unity3d.com/Packages/com.unity.xr.interaction.toolkit@2.1/api/UnityEngine.XR.Interaction.Toolkit.XRSocketInteractor.html")]
public class XRSocketInteractor : XRBaseInteractor, IXRHoverInteractor, IXRSelectInteractor, IXRInteractor
Properties
interactableCantHoverMeshMaterial
Material used for rendering interactable meshes on hover when there is already a selected object in the socket (a default material will be created if none is supplied).
Declaration
public Material interactableCantHoverMeshMaterial { get; set; }
Property Value
Type | Description |
---|---|
Material |
interactableHoverMeshMaterial
Material used for rendering interactable meshes on hover (a default material will be created if none is supplied).
Declaration
public Material interactableHoverMeshMaterial { get; set; }
Property Value
Type | Description |
---|---|
Material |
interactableHoverScale
Scale at which to render hovered Interactable.
Declaration
public float interactableHoverScale { get; set; }
Property Value
Type | Description |
---|---|
Single |
isHoverActive
(Read Only) Indicates whether this Interactor is in a state where it could hover.
Declaration
public override bool isHoverActive { get; }
Property Value
Type | Description |
---|---|
Boolean |
Overrides
isSelectActive
(Read Only) Indicates whether this Interactor is in a state where it could select.
Declaration
public override bool isSelectActive { get; }
Property Value
Type | Description |
---|---|
Boolean |
Overrides
recycleDelayTime
Sets the amount of time the socket will refuse hovers after an object is removed.
Declaration
public float recycleDelayTime { get; set; }
Property Value
Type | Description |
---|---|
Single |
selectedInteractableMovementTypeOverride
(Read Only) Overriding movement type of the selected Interactable's movement. By default, this does not override the movement type.
Declaration
public override XRBaseInteractable.MovementType? selectedInteractableMovementTypeOverride { get; }
Property Value
Type | Description |
---|---|
Nullable<XRBaseInteractable.MovementType> |
Overrides
Remarks
You can use this to change the effective movement type of an Interactable for different Interactors. An example would be having an Interactable use VelocityTracking so it does not move through geometry with a Collider when interacting with it using a Ray or Direct Interactor, but have a Socket Interactor override the movement type to be Instantaneous for reduced movement latency.
See Also
showInteractableHoverMeshes
Whether this socket should show a mesh at socket's attach point for Interactables that it is hovering over.
Declaration
public bool showInteractableHoverMeshes { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Remarks
The interactable's attach transform must not change parent Transform while selected for the position and rotation of the hover mesh to be correctly calculated.
socketActive
Whether socket interaction is enabled.
Declaration
public bool socketActive { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
unsortedValidTargets
The set of Interactables that this Interactor could possibly interact with this frame. This list is not sorted by priority.
Declaration
protected List<IXRInteractable> unsortedValidTargets { get; }
Property Value
Type | Description |
---|---|
List<IXRInteractable> |
See Also
Methods
Awake()
See MonoBehaviour.
Declaration
protected override void Awake()
Overrides
CanHover(IXRHoverInteractable)
Determines if the Interactable is valid for hover this frame.
Declaration
public override bool CanHover(IXRHoverInteractable interactable)
Parameters
Type | Name | Description |
---|---|---|
IXRHoverInteractable | interactable | Interactable to check. |
Returns
Type | Description |
---|---|
Boolean | Returns true if the Interactable can be hovered over this frame. |
Overrides
See Also
CanHover(XRBaseInteractable)
Determines if the Interactable is valid for hover this frame.
Declaration
[Obsolete("CanHover(XRBaseInteractable) has been deprecated. Use CanHover(IXRHoverInteractable) instead.")]
public override bool CanHover(XRBaseInteractable interactable)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractable | interactable | Interactable to check. |
Returns
Type | Description |
---|---|
Boolean | Returns true if the interactable can be hovered over this frame. |
Overrides
Remarks
CanHover(XRBaseInteractable)
has been deprecated. Use CanHover(IXRHoverInteractable) instead.
See Also
CanSelect(IXRSelectInteractable)
Determines if the Interactable is valid for selection this frame.
Declaration
public override bool CanSelect(IXRSelectInteractable interactable)
Parameters
Type | Name | Description |
---|---|---|
IXRSelectInteractable | interactable | Interactable to check. |
Returns
Type | Description |
---|---|
Boolean | Returns true if the Interactable can be selected this frame. |
Overrides
See Also
CanSelect(XRBaseInteractable)
Determines if the Interactable is valid for selection this frame.
Declaration
[Obsolete("CanSelect(XRBaseInteractable) has been deprecated. Use CanSelect(IXRSelectInteractable) instead.")]
public override bool CanSelect(XRBaseInteractable interactable)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractable | interactable | Interactable to check. |
Returns
Type | Description |
---|---|
Boolean | Returns true if the Interactable can be selected this frame. |
Overrides
Remarks
CanSelect(XRBaseInteractable)
has been deprecated. Use CanSelect(IXRSelectInteractable) instead.
See Also
CreateDefaultHoverMaterials()
Creates the default hover materials for interactableHoverMeshMaterial and interactableCantHoverMeshMaterial if necessary.
Declaration
protected virtual void CreateDefaultHoverMaterials()
DrawHoveredInteractables()
Unity calls this method automatically in order to draw the Interactables that are currently being hovered over.
Declaration
protected virtual void DrawHoveredInteractables()
GetValidTargets(List<IXRInteractable>)
Retrieve the list of Interactables that this Interactor could possibly interact with this frame. This list is sorted by priority (with highest priority first).
Declaration
public override void GetValidTargets(List<IXRInteractable> targets)
Parameters
Type | Name | Description |
---|---|---|
List<IXRInteractable> | targets | The results list to populate with Interactables that are valid for selection or hover. |
Overrides
Remarks
When implementing this method, Unity expects you to clear targets
before adding to it.
OnHoverEntering(HoverEnterEventArgs)
The XRInteractionManager calls this method right before the Interactor first initiates hovering over an Interactable in a first pass.
Declaration
protected override void OnHoverEntering(HoverEnterEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
HoverEnterEventArgs | args | Event data containing the Interactable that is being hovered over. |
Overrides
Remarks
args
is only valid during this method call, do not hold a reference to it.
See Also
OnHoverExiting(HoverExitEventArgs)
The XRInteractionManager calls this method right before the Interactor ends hovering over an Interactable in a first pass.
Declaration
protected override void OnHoverExiting(HoverExitEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
HoverExitEventArgs | args | Event data containing the Interactable that is no longer hovered over. |
Overrides
Remarks
args
is only valid during this method call, do not hold a reference to it.
See Also
OnRegistered(InteractorRegisteredEventArgs)
The XRInteractionManager calls this method when this Interactor is registered with it.
Declaration
protected override void OnRegistered(InteractorRegisteredEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
InteractorRegisteredEventArgs | args | Event data containing the Interaction Manager that registered this Interactor. |
Overrides
Remarks
args
is only valid during this method call, do not hold a reference to it.
See Also
OnSelectExiting(SelectExitEventArgs)
The XRInteractionManager calls this method right before the Interactor ends selection of an Interactable in a first pass.
Declaration
protected override void OnSelectExiting(SelectExitEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
SelectExitEventArgs | args | Event data containing the Interactable that is no longer selected. |
Overrides
Remarks
args
is only valid during this method call, do not hold a reference to it.
See Also
OnTriggerEnter(Collider)
See MonoBehaviour.
Declaration
protected void OnTriggerEnter(Collider other)
Parameters
Type | Name | Description |
---|---|---|
Collider | other | The other Collider involved in this collision. |
OnTriggerExit(Collider)
See MonoBehaviour.
Declaration
protected void OnTriggerExit(Collider other)
Parameters
Type | Name | Description |
---|---|---|
Collider | other | The other Collider involved in this collision. |
OnTriggerStay(Collider)
See MonoBehaviour.
Declaration
protected void OnTriggerStay(Collider other)
Parameters
Type | Name | Description |
---|---|---|
Collider | other | The other Collider involved in this collision. |
OnUnregistered(InteractorUnregisteredEventArgs)
The XRInteractionManager calls this method when this Interactor is unregistered from it.
Declaration
protected override void OnUnregistered(InteractorUnregisteredEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
InteractorUnregisteredEventArgs | args | Event data containing the Interaction Manager that unregistered this Interactor. |
Overrides
Remarks
args
is only valid during this method call, do not hold a reference to it.
See Also
ProcessInteractor(XRInteractionUpdateOrder.UpdatePhase)
The XRInteractionManager calls this method to update the Interactor after interaction events occur.
Declaration
public override void ProcessInteractor(XRInteractionUpdateOrder.UpdatePhase updatePhase)
Parameters
Type | Name | Description |
---|---|---|
XRInteractionUpdateOrder.UpdatePhase | updatePhase | The update phase this is called during. |
Overrides
Remarks
Please see the XRInteractionManager and XRInteractionUpdateOrder.UpdatePhase documentation for more details on update order.
See Also
ShouldDrawHoverMesh(MeshFilter, Renderer, Camera)
Unity calls this method automatically in order to determine whether the mesh should be drawn.
Declaration
protected virtual bool ShouldDrawHoverMesh(MeshFilter meshFilter, Renderer meshRenderer, Camera mainCamera)
Parameters
Type | Name | Description |
---|---|---|
MeshFilter | meshFilter | The MeshFilter which will be drawn when returning true. |
Renderer | meshRenderer | The Renderer on the same GameObject as the |
Camera | mainCamera | The Main Camera. |
Returns
Type | Description |
---|---|
Boolean | Returns true if the mesh should be drawn. Otherwise, returns false. |
See Also
Start()
See MonoBehaviour.
Declaration
protected override void Start()