using System;
using UnityEngine.XR.ARSubsystems;
namespace UnityEngine.XR.ARFoundation
{
///
/// Represents a raycast that updates automatically.
///
///
/// Generated by the . Create a raycast with
/// .
///
/// Related information: AR Raycast Manager component
///
[DefaultExecutionOrder(ARUpdateOrder.k_Raycast)]
[DisallowMultipleComponent]
[HelpURL(typeof(ARRaycast))]
public sealed class ARRaycast : ARTrackable
{
bool m_Updated;
///
/// The distance, in meters, between the raycast's origin and intersection point.
///
public float distance => sessionRelativeData.distance;
///
/// The hit by the raycast, or `null` if the raycast does not intersect a plane.
///
public ARPlane plane { get; internal set; }
///
/// Invoked whenever this raycast is updated. The event is fired during this `MonoBehaviour`'s
/// [Update](https://docs.unity3d.com/ScriptReference/MonoBehaviour.Update.html) callback. This event is not
/// invoked if this component is [disabled](https://docs.unity3d.com/ScriptReference/Behaviour-enabled.html),
/// although it might continue to receive positional updates.
///
public event Action updated;
///
/// Marks this raycast as updated, causing the event to be invoked during the Update
/// callback.
///
protected internal override void OnAfterSetSessionRelativeData() => m_Updated = true;
void Update()
{
if (m_Updated)
{
updated?.Invoke(new ARRaycastUpdatedEventArgs
{
raycast = this
});
m_Updated = false;
}
}
}
}