Class XRSocketInteractor
Interactor used for holding interactables via a socket.
Implements
Inherited Members
Namespace: UnityEngine .XR.Interaction.Toolkit.Interactors
Assembly: Unity.XR.Interaction.Toolkit.dll
Syntax
[MovedFrom("UnityEngine.XR.Interaction.Toolkit")]
[DisallowMultipleComponent]
[AddComponentMenu("XR/Interactors/XR Socket Interactor", 11)]
[HelpURL("https://docs.unity3d.com/Packages/com.unity.xr.interaction.toolkit@3.1/api/UnityEngine.XR.Interaction.Toolkit.Interactors.XRSocketInteractor.html")]
public class XRSocketInteractor : XRBaseInteractor, IXRHoverInteractor, IXRSelectInteractor, IXRTargetPriorityInteractor, IXRGroupMember, IXRInteractionStrengthInteractor, IXRInteractor
Remarks
A socket is defined as the target for a specific interactable, such as a keyhole for a key
or a battery socket for a battery. Not to be confused with network programming.
This component is not designed to use input (thus does not derive from XRBase
Properties
ejectExistingSocketsWhenSnapping
Determines if when snapping to a socket, any existing sockets should be ejected.
Declaration
protected virtual bool ejectExistingSocketsWhenSnapping { get; }
Property Value
Type | Description |
---|---|
bool |
fixedScale
Scale factor applied to the interactable when scale mode is set to Fixed.
Declaration
public Vector3 fixedScale { get; set; }
Property Value
Type | Description |
---|---|
Vector3 |
See Also
hoverSocketSnapping
Determines if the interactable should snap to the socket's attach transform when hovering.
Note this will cause z-fighting with the hover mesh visuals, so it is recommended to disable show
Declaration
public bool hoverSocketSnapping { get; set; }
Property Value
Type | Description |
---|---|
bool |
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 |
---|---|
float |
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 |
---|---|
bool |
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 |
---|---|
bool |
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 |
---|---|
float |
Remarks
Does nothing if hover
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 |
---|---|
XRBase |
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 Velocity
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 |
---|---|
bool |
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 |
---|---|
bool |
socketScaleMode
Scale mode used to calculate the scale factor applied to the interactable when hovering.
Declaration
public SocketScaleMode socketScaleMode { get; set; }
Property Value
Type | Description |
---|---|
Socket |
See Also
socketSnappingLimit
Maximum number of interactables this interactor can socket. Used for hover socket snapping evaluation.
Declaration
protected virtual int socketSnappingLimit { get; }
Property Value
Type | Description |
---|---|
int |
socketSnappingRadius
When socket snapping is enabled, this is the radius within which the interactable will snap to the socket's attach transform while hovering.
Declaration
public float socketSnappingRadius { get; set; }
Property Value
Type | Description |
---|---|
float |
targetBoundsSize
Bounds size used to calculate the scale factor applied to the interactable when scale mode is set to Stretched
Declaration
public Vector3 targetBoundsSize { get; set; }
Property Value
Type | Description |
---|---|
Vector3 |
See Also
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 Mono
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 |
---|---|---|
IXRHover |
interactable | Interactable to check. |
Returns
Overrides
See Also
CanHoverSnap(IXRInteractable)
Determines whether the specified IXRInteractable object can hover snap.
Declaration
protected virtual bool CanHoverSnap(IXRInteractable interactable)
Parameters
Type | Name | Description |
---|---|---|
IXRInteractable | interactable | The IXRInteractable object to check for hover snap capability. |
Returns
Type | Description |
---|---|
bool | Returns true if hover socket snapping is enabled and the interactable has no selection or is selecting; otherwise, false. |
Remarks
This method checks whether hover socket snapping is allowed and whether the specified interactable has no current selection or is in the process of selecting.
CanSelect(IXRSelectInteractable)
Determines if the Interactable is valid for selection this frame.
Declaration
public override bool CanSelect(IXRSelectInteractable interactable)
Parameters
Type | Name | Description |
---|---|---|
IXRSelect |
interactable | Interactable to check. |
Returns
Overrides
See Also
CreateDefaultHoverMaterials()
Creates the default hover materials
for interactable
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()
See Also
EndSocketSnapping(XRGrabInteractable)
Ends socket snapping for a specified XRGrab
Declaration
protected virtual bool EndSocketSnapping(XRGrabInteractable grabInteractable)
Parameters
Type | Name | Description |
---|---|---|
XRGrab |
grabInteractable | The XRGrab |
Returns
Type | Description |
---|---|
bool | Returns true if the specified grab interactable was found and removed; otherwise, false. |
Remarks
Removes the specified grab interactable from the local interactables with socket transformer list and removes it from the socket grab transformer.
See Also
GetHoveredInteractableMaterial(IXRHoverInteractable)
Gets the material used to draw the given hovered Interactable.
Declaration
protected virtual Material GetHoveredInteractableMaterial(IXRHoverInteractable interactable)
Parameters
Type | Name | Description |
---|---|---|
IXRHover |
interactable | The hovered Interactable to get the material for. |
Returns
Type | Description |
---|---|
Material | Returns the material Unity should use to draw the given hovered Interactable. |
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.
OnDisable()
See Mono
Declaration
protected override void OnDisable()
Overrides
OnEnable()
See Mono
Declaration
protected override void OnEnable()
Overrides
OnHoverEntered(HoverEnterEventArgs)
The XRInteraction
Declaration
protected override void OnHoverEntered(HoverEnterEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
Hover |
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
OnHoverEntering(HoverEnterEventArgs)
The XRInteraction
Declaration
protected override void OnHoverEntering(HoverEnterEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
Hover |
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 XRInteraction
Declaration
protected override void OnHoverExiting(HoverExitEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
Hover |
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 XRInteraction
Declaration
protected override void OnRegistered(InteractorRegisteredEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
Interactor |
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
OnSelectEntered(SelectEnterEventArgs)
The XRInteraction
Declaration
protected override void OnSelectEntered(SelectEnterEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
Select |
args | Event data containing the Interactable that is being selected. |
Overrides
Remarks
args
is only valid during this method call, do not hold a reference to it.
See Also
OnSelectExited(SelectExitEventArgs)
The XRInteraction
Declaration
protected override void OnSelectExited(SelectExitEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
Select |
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
OnSelectExiting(SelectExitEventArgs)
The XRInteraction
Declaration
protected override void OnSelectExiting(SelectExitEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
Select |
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 Mono
Declaration
protected void OnTriggerEnter(Collider other)
Parameters
OnTriggerExit(Collider)
See Mono
Declaration
protected void OnTriggerExit(Collider other)
Parameters
OnTriggerStay(Collider)
See Mono
Declaration
protected void OnTriggerStay(Collider other)
Parameters
OnUnregistered(InteractorUnregisteredEventArgs)
The XRInteraction
Declaration
protected override void OnUnregistered(InteractorUnregisteredEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
Interactor |
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
OnValidate()
See Mono
Declaration
protected virtual void OnValidate()
ProcessInteractor(UpdatePhase)
The XRInteraction
Declaration
public override void ProcessInteractor(XRInteractionUpdateOrder.UpdatePhase updatePhase)
Parameters
Type | Name | Description |
---|---|---|
XRInteraction |
updatePhase | The update phase this is called during. |
Overrides
Remarks
Please see the XRInteraction
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 |
---|---|---|
Mesh |
meshFilter | The Mesh |
Renderer | meshRenderer | The Renderer on the same Game |
Camera | mainCamera | The Main Camera. |
Returns
See Also
StartSocketSnapping(XRGrabInteractable)
Initiates socket snapping for a specified XRGrab
Declaration
protected virtual bool StartSocketSnapping(XRGrabInteractable grabInteractable)
Parameters
Type | Name | Description |
---|---|---|
XRGrab |
grabInteractable | The XRGrab |
Returns
Type | Description |
---|---|
bool | Returns true if the operation is successful; false if the socket snapping has already started for the interactable or if the number of interactables with socket transformer exceeds the socket limit. |
Remarks
If the socket snapping has already started for the interactable, or if the number of interactables with socket transformer exceeds the socket limit, the method does nothing. Otherwise, it adds the specified grab interactable to the socket grab transformer and adds it to the global and local interactables with socket transformer lists.