ARRaycast.cs
2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using UnityEngine.XR.ARSubsystems;
namespace UnityEngine.XR.ARFoundation
{
/// <summary>
/// Represents a raycast that updates automatically.
/// </summary>
/// <remarks>
/// Generated by the <see cref="ARRaycastManager"/>. Create a raycast with
/// <see cref="ARRaycastManager.AddRaycast(Vector2, float)"/>.
/// </remarks>
[DefaultExecutionOrder(ARUpdateOrder.k_Raycast)]
[DisallowMultipleComponent]
[HelpURL(HelpUrls.ApiWithNamespace + nameof(ARRaycast) + ".html")]
public sealed class ARRaycast : ARTrackable<XRRaycast, ARRaycast>
{
bool m_Updated;
/// <summary>
/// Get a native pointer associated with this raycast.
/// </summary>
/// <remarks>
/// The data pointed to by this member is implementation defined.
/// The lifetime of the pointed to object is also
/// implementation defined, but should be valid at least until the next
/// <see cref="ARSession"/> update.
/// </remarks>
public IntPtr nativePtr => sessionRelativeData.nativePtr;
/// <summary>
/// The distance, in meters, between the raycast's origin and intersection point.
/// </summary>
public float distance => sessionRelativeData.distance;
/// <summary>
/// The <see cref="ARPlane"/> hit by the raycast, or `null` if the raycast does not intersect a plane.
/// </summary>
public ARPlane plane { get; internal set; }
/// <summary>
/// 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 may continue to receive positional updates.
/// </summary>
public event Action<ARRaycastUpdatedEventArgs> updated;
/// <summary>
/// Marks this raycast as updated, causing the <see cref="updated"/> event to be invoked during the Update
/// callback.
/// </summary>
protected internal override void OnAfterSetSessionRelativeData() => m_Updated = true;
void Update()
{
if (m_Updated)
{
updated?.Invoke(new ARRaycastUpdatedEventArgs
{
raycast = this
});
m_Updated = false;
}
}
}
}