Class ARRaycastManager
Manages an XRRaycastSubsystem
, exposing raycast functionality in AR Foundation. Use this component
to raycast against trackables (that is, detected features in the physical environment) when they do not have
a presence in the Physics world.
Inheritance
Implements
Inherited Members
Namespace: UnityEngine.XR.ARFoundation
Assembly: Unity.XR.ARFoundation.dll
Syntax
[DefaultExecutionOrder(-2147483647)]
[DisallowMultipleComponent]
[RequireComponent(typeof(XROrigin))]
[AddComponentMenu("XR/AR Foundation/AR Raycast Manager")]
public sealed class ARRaycastManager : ARTrackableManager<XRRaycastSubsystem, XRRaycastSubsystemDescriptor, XRRaycastSubsystem.Provider, XRRaycast, ARRaycast>, ITrackablesChanged<ARRaycast>
Remarks
Related information: AR Raycast Manager component
Properties
gameObjectName
The name of the GameObject
for each instantiated ARRaycast.
Declaration
protected override string gameObjectName { get; }
Property Value
Type | Description |
---|---|
string |
Overrides
raycastPrefab
If not null, this prefab will be instantiated for each ARRaycast.
Declaration
public GameObject raycastPrefab { get; set; }
Property Value
Type | Description |
---|---|
GameObject |
Methods
AddRaycast(Vector2, float)
Creates an ARRaycast that updates automatically. ARRaycasts will continue to update until you remove them with RemoveRaycast(ARRaycast) or disable this component.
Declaration
public ARRaycast AddRaycast(Vector2 screenPoint, float estimatedDistance)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | screenPoint | A point on the screen, in pixels. |
float | estimatedDistance | The estimated distance to the intersection point. This can be used to determine a potential intersection before the environment has been fully mapped. |
Returns
Type | Description |
---|---|
ARRaycast | A new ARRaycast if successful; otherwise |
GetPrefab()
Gets the Prefab that should be instantiated for each ARRaycast. Can be null
.
Declaration
protected override GameObject GetPrefab()
Returns
Type | Description |
---|---|
GameObject | The Prefab that should be instantiated for each ARRaycast. |
Overrides
OnAfterSetSessionRelativeData(ARRaycast, XRRaycast)
Invoked just after a ARRaycast has been updated.
Declaration
protected override void OnAfterSetSessionRelativeData(ARRaycast raycast, XRRaycast sessionRelativeData)
Parameters
Type | Name | Description |
---|---|---|
ARRaycast | raycast | The ARRaycast being updated. |
XRRaycast | sessionRelativeData | The new data associated with the raycast. All spatial data is is session-relative space. |
Overrides
OnAfterStart()
Invoked just after the subsystem has been Start
ed. Used to set raycast delegates internally.
Declaration
protected override void OnAfterStart()
Overrides
Raycast(Ray, List<ARRaycastHit>, TrackableType)
Cast a Ray
against trackables, that is, detected features such as planes.
Declaration
public bool Raycast(Ray ray, List<ARRaycastHit> hitResults, TrackableType trackableTypes = (TrackableType)-1)
Parameters
Type | Name | Description |
---|---|---|
Ray | ray | The |
List<ARRaycastHit> | hitResults | Contents are replaced with the raycast results, if successful. Results are sorted by distance in closest-first order. |
TrackableType | trackableTypes | (Optional) The types of trackables to cast against. |
Returns
Type | Description |
---|---|
bool | true if the raycast hit a trackable in the |
Raycast(Vector2, List<ARRaycastHit>, TrackableType)
Cast a ray from a point in screen space against trackables, that is, detected features such as planes.
Declaration
public bool Raycast(Vector2 screenPoint, List<ARRaycastHit> hitResults, TrackableType trackableTypes = (TrackableType)-1)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | screenPoint | The point, in device screen pixels, from which to cast. |
List<ARRaycastHit> | hitResults | Contents are replaced with the raycast results, if successful. Results are sorted by distance in closest-first order. |
TrackableType | trackableTypes | (Optional) The types of trackables to cast against. |
Returns
Type | Description |
---|---|
bool | true if the raycast hit a trackable in the |
RemoveRaycast(ARRaycast)
Removes an existing ARRaycast.
Declaration
public void RemoveRaycast(ARRaycast raycast)
Parameters
Type | Name | Description |
---|---|---|
ARRaycast | raycast | The ARRaycast to remove. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |