Class XRRayInteractor
Interactor used for interacting with interactables at a distance. This is handled via raycasts that update the current set of valid targets for this interactor.
Inheritance
Inherited Members
Namespace: UnityEngine.XR.Interaction.Toolkit
Syntax
[DisallowMultipleComponent]
[AddComponentMenu("XR/XR Ray Interactor")]
public class XRRayInteractor : XRBaseControllerInteractor, IUIInteractor, ILineRenderable
Properties
acceleration
Gravity of the projectile in the reference frame.
Declaration
public float acceleration { get; set; }
Property Value
Type | Description |
---|---|
Single |
Acceleration
Declaration
[Obsolete("Acceleration has been deprecated. Use acceleration instead. (UnityUpgradable) -> acceleration")]
public float Acceleration { get; set; }
Property Value
Type | Description |
---|---|
Single |
additionalFlightTime
Additional flight time after the projectile lands at the same height of the start point in the tracking space. Increase this value will make the end point drop lower in height.
Declaration
public float additionalFlightTime { get; set; }
Property Value
Type | Description |
---|---|
Single |
AdditionalFlightTime
Declaration
[Obsolete("AdditionalFlightTime has been deprecated. Use additionalFlightTime instead. (UnityUpgradable) -> additionalFlightTime")]
public float AdditionalFlightTime { get; set; }
Property Value
Type | Description |
---|---|
Single |
allowAnchorControl
Allows the user to move the attach anchor point using the joystick.
Declaration
public bool allowAnchorControl { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
See Also
angle
Gets the signed angle between the controller's forward direction and the tracking space.
Declaration
public float angle { get; }
Property Value
Type | Description |
---|---|
Single |
Angle
Declaration
[Obsolete("Angle has been deprecated. Use angle instead. (UnityUpgradable) -> angle")]
public float Angle { get; }
Property Value
Type | Description |
---|---|
Single |
controlPointDistance
Increase this value will make the peak of the curve further from the start point.
Declaration
public float controlPointDistance { get; set; }
Property Value
Type | Description |
---|---|
Single |
controlPointHeight
Increase this value will make the peak of the curve higher relative to the start point.
Declaration
public float controlPointHeight { get; set; }
Property Value
Type | Description |
---|---|
Single |
enableUIInteraction
Gets or sets whether this interactor is able to affect UI.
Declaration
public bool enableUIInteraction { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
endPointDistance
Increase this value distance will make the end of curve further from the start point.
Declaration
public float endPointDistance { get; set; }
Property Value
Type | Description |
---|---|
Single |
endPointHeight
Decrease this value will make the end of the curve drop lower relative to the start point.
Declaration
public float endPointHeight { get; set; }
Property Value
Type | Description |
---|---|
Single |
hitDetectionType
Sets which type of hit detection to use for the raycast.
Declaration
public XRRayInteractor.HitDetectionType hitDetectionType { get; set; }
Property Value
Type | Description |
---|---|
XRRayInteractor.HitDetectionType |
hoverTimeToSelect
Gets or sets the number of seconds for which this interactor must hover over an object to select it if Hover To Select is enabled.
Declaration
public float hoverTimeToSelect { get; set; }
Property Value
Type | Description |
---|---|
Single |
hoverToSelect
Gets or sets whether this uses hovering for a time period to select the interactable being hovered.
Declaration
public bool hoverToSelect { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
keepSelectedTargetValid
Whether to keep selecting the target when not pointing to it after initially selecting it. It is recommended to set this value to true for grabbing objects, false for teleportation interactables.
Declaration
public bool keepSelectedTargetValid { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
lineType
Gets or sets the type of ray cast.
Declaration
public XRRayInteractor.LineType lineType { get; set; }
Property Value
Type | Description |
---|---|
XRRayInteractor.LineType |
maxRaycastDistance
Gets or sets the max distance of ray cast. Increase this value will let you reach further.
Declaration
public float maxRaycastDistance { get; set; }
Property Value
Type | Description |
---|---|
Single |
originalAttachTransform
The Transform that upon entering selection (when this interactor first initiates selection of an interactable), this interactor will copy the pose of the attach Transform values into.
Declaration
protected Transform originalAttachTransform { get; set; }
Property Value
Type | Description |
---|---|
Transform |
Remarks
Automatically instantiated and set in Awake(). Setting this will not automatically destroy the previous object.
See Also
raycastMask
Gets or sets layer mask used for limiting raycast targets.
Declaration
public LayerMask raycastMask { get; set; }
Property Value
Type | Description |
---|---|
LayerMask |
raycastTriggerInteraction
Gets or sets type of interaction with trigger volumes via raycast.
Declaration
public QueryTriggerInteraction raycastTriggerInteraction { get; set; }
Property Value
Type | Description |
---|---|
QueryTriggerInteraction |
referenceFrame
Gets or sets the reference frame of the projectile. If not set it will try to find the rig object, and if that does not exist it will use its own Transform by default.
Declaration
public Transform referenceFrame { get; set; }
Property Value
Type | Description |
---|---|
Transform |
rotateSpeed
Speed that the anchor is rotated.
Declaration
public float rotateSpeed { get; set; }
Property Value
Type | Description |
---|---|
Single |
See Also
sampleFrequency
Gets or sets the number of sample points of the curve, should be at least 3, the higher the better quality.
Declaration
public int sampleFrequency { get; set; }
Property Value
Type | Description |
---|---|
Int32 |
sphereCastRadius
Gets or sets radius used for sphere casting. Will use regular raycasting if set to 0 or less.
Declaration
public float sphereCastRadius { get; set; }
Property Value
Type | Description |
---|---|
Single |
translateSpeed
Speed that the anchor is translated.
Declaration
public float translateSpeed { get; set; }
Property Value
Type | Description |
---|---|
Single |
See Also
useForceGrab
Force grab moves the object to your hand rather than interacting with it at a distance.
Declaration
public bool useForceGrab { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
validTargets
List of interactables that this interactor could possibly interact with this frame. Populated during ProcessInteractor(XRInteractionUpdateOrder.UpdatePhase).
Declaration
protected override List<XRBaseInteractable> validTargets { get; }
Property Value
Type | Description |
---|---|
List<XRBaseInteractable> |
Overrides
velocity
Initial velocity of the projectile. Increase this value will make the curve reach further.
Declaration
public float velocity { get; set; }
Property Value
Type | Description |
---|---|
Single |
Velocity
Declaration
[Obsolete("Velocity has been deprecated. Use velocity instead. (UnityUpgradable) -> velocity")]
public float Velocity { get; set; }
Property Value
Type | Description |
---|---|
Single |
Methods
Awake()
Declaration
protected override void Awake()
Overrides
CanHover(XRBaseInteractable)
Determines if the interactable is valid for hover this frame.
Declaration
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
CanSelect(XRBaseInteractable)
Determines if the interactable is valid for selection this frame.
Declaration
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
GetCurrentRaycastHit(out RaycastHit)
This function will return the first raycast result, if any raycast results are available.
Declaration
public bool GetCurrentRaycastHit(out RaycastHit raycastHit)
Parameters
Type | Name | Description |
---|---|---|
RaycastHit | raycastHit | When this method returns, contains the raycast result if available; otherwise, the default value. |
Returns
Type | Description |
---|---|
Boolean | Returns true if the |
GetLinePoints(ref Vector3[], out Int32)
Performs the computation to convert the sample points from their local positions to world space and outputs an array of those points to form a line.
Declaration
public bool GetLinePoints(ref Vector3[] linePoints, out int numPoints)
Parameters
Type | Name | Description |
---|---|---|
Vector3[] | linePoints | When this method returns, contains the sample points if successful. |
Int32 | numPoints | When this method returns, contains the number of sample points if successful. |
Returns
Type | Description |
---|---|
Boolean | Returns true if the sample points form a valid line, such as by having at least two points. Returns false otherwise. |
Implements
GetLinePoints(ref Vector3[], ref Int32, Int32)
(Obsolete) Use GetLinePoints(ref Vector3[], out Int32) instead.
Declaration
[Obsolete("GetLinePoints with ref int parameter has been deprecated. Use signature with out int parameter instead.")]
public bool GetLinePoints(ref Vector3[] linePoints, ref int numPoints, int _ = 0)
Parameters
Type | Name | Description |
---|---|---|
Vector3[] | linePoints | Obsolete. |
Int32 | numPoints | Obsolete. |
Int32 | _ | Dummy value to support old function signature. |
Returns
Type | Description |
---|---|
Boolean | Obsolete. |
GetValidTargets(List<XRBaseInteractable>)
Retrieve the list of interactables that this interactor could possibly interact with this frame. This list is sorted by priority (in this case distance).
Declaration
public override void GetValidTargets(List<XRBaseInteractable> validTargets)
Parameters
Type | Name | Description |
---|---|---|
List<XRBaseInteractable> | validTargets | Populated List of interactables that are valid for selection or hover. |
Overrides
OnDisable()
Declaration
protected override void OnDisable()
Overrides
OnEnable()
Declaration
protected override void OnEnable()
Overrides
OnSelectEntering(XRBaseInteractable)
Declaration
protected override void OnSelectEntering(XRBaseInteractable interactable)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractable | interactable |
Overrides
OnSelectExiting(XRBaseInteractable)
This method is called by the interaction manager right before the interactor ends selection of an interactable.
Declaration
protected override void OnSelectExiting(XRBaseInteractable interactable)
Parameters
Type | Name | Description |
---|---|---|
XRBaseInteractable | interactable | Interactable that is no longer selected. |
Overrides
See Also
OnValidate()
Declaration
protected void OnValidate()
ProcessInteractor(XRInteractionUpdateOrder.UpdatePhase)
This method is called by the interaction manager to update the interactor. Please see the interaction manager documentation for more details on update order.
Declaration
public override void ProcessInteractor(XRInteractionUpdateOrder.UpdatePhase updatePhase)
Parameters
Type | Name | Description |
---|---|---|
XRInteractionUpdateOrder.UpdatePhase | updatePhase |
Overrides
RotateAnchor(Transform, Single)
Declaration
protected virtual void RotateAnchor(Transform anchor, float directionAmount)
Parameters
Type | Name | Description |
---|---|---|
Transform | anchor | |
Single | directionAmount |
TranslateAnchor(Transform, Transform, Single)
Declaration
protected virtual void TranslateAnchor(Transform originalAnchor, Transform anchor, float directionAmount)
Parameters
Type | Name | Description |
---|---|---|
Transform | originalAnchor | |
Transform | anchor | |
Single | directionAmount |
TryGetHitInfo(out Vector3, out Vector3, out Int32, out Boolean)
Gets the current raycast hit information., it will return the world position and the normal vector of the hit point, and its position in linePoints.
Declaration
public bool TryGetHitInfo(out Vector3 position, out Vector3 normal, out int positionInLine, out bool isValidTarget)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | position | When this method returns, contains the world position of the ray impact point if the raycast result is valid. |
Vector3 | normal | When this method returns, contains the world normal of the surface the ray hit if the raycast result is valid. |
Int32 | positionInLine | When this method returns, contains the index within the list of raycast points returned by GetLinePoints(ref Vector3[], out Int32). |
Boolean | isValidTarget | When this method returns, contains whether both the raycast result is valid and a valid target for interaction. |
Returns
Type | Description |
---|---|
Boolean | Returns true if the raycast result is valid. Returns false otherwise. |
Implements
TryGetHitInfo(ref Vector3, ref Vector3, ref Int32, ref Boolean, Int32)
(Obsolete) Use TryGetHitInfo(out Vector3, out Vector3, out Int32, out Boolean) instead.
Declaration
[Obsolete("TryGetHitInfo with ref parameters has been deprecated. Use signature with out parameters instead.")]
public bool TryGetHitInfo(ref Vector3 position, ref Vector3 normal, ref int positionInLine, ref bool isValidTarget, int _ = 0)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | position | Obsolete. |
Vector3 | normal | Obsolete. |
Int32 | positionInLine | Obsolete. |
Boolean | isValidTarget | Obsolete. |
Int32 | _ | Dummy value to support old function signature. |
Returns
Type | Description |
---|---|
Boolean | Obsolete. |
TryGetUIModel(out TrackedDeviceModel)
Attempts to retrieve the current UI Model.
Declaration
public bool TryGetUIModel(out TrackedDeviceModel model)
Parameters
Type | Name | Description |
---|---|---|
TrackedDeviceModel | model | The returned model that reflects the UI state of this Interactor. |
Returns
Type | Description |
---|---|
Boolean | Returns true if the model was able to retrieved. Returns false otherwise. |
Implements
UpdateUIModel(ref TrackedDeviceModel)
Updates the current UI Model to match the state of the Interactor.
Declaration
public void UpdateUIModel(ref TrackedDeviceModel model)
Parameters
Type | Name | Description |
---|---|---|
TrackedDeviceModel | model | The returned model that will match this Interactor. |