Class XRDirectInteractor
Interactor used for directly interacting with interactables that are touching. This is handled via trigger volumes that update the current set of valid targets for this interactor. This component must have a collision volume that is set to be a trigger to work.
Inheritance
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 Direct Interactor", 11)]
[HelpURL("https://docs.unity3d.com/Packages/com.unity.xr.interaction.toolkit@3.0/api/UnityEngine.XR.Interaction.Toolkit.Interactors.XRDirectInteractor.html")]
public class XRDirectInteractor : XRBaseInputInteractor, IXRHoverInteractor, IXRSelectInteractor, IXRTargetPriorityInteractor, IXRGroupMember, IXRInteractionStrengthInteractor, IXRActivateInteractor, IXRInteractor
Properties
improveAccuracyWithSphereCollider
When a Sphere Collider component is the only collider on this interactor, and no Rigidbody component is attached, the interactor will use Burst compiler optimizations and sphere casts instead of relying on physics trigger events to evaluate direct interactions when this property is enabled. This also improves inter-frame accuracy and reliability.
Declaration
public bool improveAccuracyWithSphereCollider { get; set; }
Property Value
Type | Description |
---|---|
bool |
Remarks
Cannot change this value at runtime after Awake
.
Enabling this property can improve inter-frame reliability during fast motion when the requirements for optimization are met
by running on each Update instead of Fixed Update and using a sphere cast to determine valid targets.
Disable to force the use of trigger events, such as the OnTriggerStay
and FixedUpdate
methods.
See Also
physicsLayerMask
Physics layer mask used for limiting direct interactor overlaps when using the improveAccuracyWithSphereCollider option.
Declaration
public LayerMask physicsLayerMask { get; set; }
Property Value
Type | Description |
---|---|
LayerMask |
physicsTriggerInteraction
Determines whether the direct interactor sphere overlap will hit triggers when using the improveAccuracyWithSphereCollider option.
Declaration
public QueryTriggerInteraction physicsTriggerInteraction { get; set; }
Property Value
Type | Description |
---|---|
QueryTriggerInteraction |
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
usingSphereColliderAccuracyImprovement
Whether the requirements were successfully met to use the alternate improved collider accuracy code path.
Declaration
public bool usingSphereColliderAccuracyImprovement { get; }
Property Value
Type | Description |
---|---|
bool |
Remarks
The requirements are a single Sphere Collider component and no Rigidbody component on this GameObject.
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 |
---|---|
bool | Returns true if the Interactable can be hovered over this frame. |
Overrides
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 |
---|---|
bool | Returns true if the Interactable can be selected this frame. |
Overrides
See Also
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 MonoBehaviour.
Declaration
protected override void OnDisable()
Overrides
OnEnable()
See MonoBehaviour.
Declaration
protected override void OnEnable()
Overrides
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
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
PreprocessInteractor(UpdatePhase)
The XRInteractionManager or containing IXRInteractionGroup calls this method to update the Interactor before interaction events occur. Interactors should use this method to do tasks like determine their valid targets.
Declaration
public override void PreprocessInteractor(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
ProcessInteractor(UpdatePhase)
The XRInteractionManager or containing IXRInteractionGroup 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.