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.
Inherited Members
Namespace: UnityEngine.XR.Interaction.Toolkit
Syntax
public class XRRayInteractor : XRBaseControllerInteractor, IUIInteractable, ILineRenderable
Properties
Acceleration
Gravity of the projectile in the reference frame.
Declaration
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 |
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 |
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 |
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 |
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 XRRig object, if the XRRig does not exist it will use self. ///
Declaration
public Transform referenceFrame { get; set; }
Property Value
| Type | Description |
|---|---|
| Transform |
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 spherecasting. Will use regular raycasting if set to 0.0f or less.
Declaration
public float sphereCastRadius { get; set; }
Property Value
| Type | Description |
|---|---|
| Single |
ValidTargets
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 |
Methods
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 |
|
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 |
|
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 | the raycastHit result that will be filled in by this function |
Returns
| Type | Description |
|---|---|
| Boolean | true if the raycastHit parameter contains a valid raycast result |
GetLinePoints(ref Vector3[], ref Int32)
This function implements the ILineRenderable interface and returns the sample points of the line.
Declaration
public bool GetLinePoints(ref Vector3[] linePoints, ref int noPoints)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3[] | linePoints | |
| Int32 | noPoints |
Returns
| Type | Description |
|---|---|
| Boolean |
Implements
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
ProcessInteractor(XRInteractionUpdateOrder.UpdatePhase)
Declaration
public override void ProcessInteractor(XRInteractionUpdateOrder.UpdatePhase updatePhase)
Parameters
| Type | Name | Description |
|---|---|---|
| XRInteractionUpdateOrder.UpdatePhase | updatePhase |
Overrides
TryGetHitInfo(ref Vector3, ref Vector3, ref Int32, ref Boolean)
This function implements the ILineRenderable interface, if there is a raycast hit, it will return the world position and the normal vector of the hit point, and its position in linePoints.
Declaration
public bool TryGetHitInfo(ref Vector3 position, ref Vector3 normal, ref int positionInLine, ref bool isValidTarget)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | position | |
| Vector3 | normal | |
| Int32 | positionInLine | |
| Boolean | isValidTarget |
Returns
| Type | Description |
|---|---|
| Boolean |
Implements
TryGetUIModel(out TrackedDeviceModel)
Attempts to retrieve the current UI Model. Returns false if not available.
Declaration
public bool TryGetUIModel(out TrackedDeviceModel model)
Parameters
| Type | Name | Description |
|---|---|---|
| TrackedDeviceModel | model | The UI Model that matches that Interactor. |
Returns
| Type | Description |
|---|---|
| Boolean |
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 model that will match this Interactor |