ARAnchor.cs
2.01 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
using System;
using UnityEngine.XR.ARSubsystems;
namespace UnityEngine.XR.ARFoundation
{
/// <summary>
/// Represents an Anchor tracked by an XR device.
/// </summary>
/// <remarks>
/// A anchor is a pose in the physical environment that is tracked by an XR device.
/// As the device refines its understanding of the environment, anchors will be
/// updated, helping you to keep virtual content connected to a real-world position and orientation.
/// </remarks>
[DefaultExecutionOrder(ARUpdateOrder.k_Anchor)]
[DisallowMultipleComponent]
[HelpURL(HelpUrls.ApiWithNamespace + nameof(ARAnchor) + ".html")]
public sealed class ARAnchor : ARTrackable<XRAnchor, ARAnchor>
{
/// <summary>
/// Get the native pointer associated with this <see cref="ARAnchor"/>.
/// </summary>
/// <remarks>
/// The data pointed to by this pointer is implementation defined. While its
/// lifetime is also implementation defined, it should be valid until at least
/// the next <see cref="ARSession"/> update.
/// </remarks>
public IntPtr nativePtr => sessionRelativeData.nativePtr;
/// <summary>
/// Get the session identifier from which this anchor originated.
/// </summary>
public Guid sessionId => sessionRelativeData.sessionId;
void OnEnable()
{
if (ARAnchorManager.instance is ARAnchorManager manager)
{
manager.TryAddAnchor(this);
}
else
{
pending = true;
}
}
void Update()
{
if (trackableId.Equals(TrackableId.invalidId) && ARAnchorManager.instance is ARAnchorManager manager)
{
manager.TryAddAnchor(this);
}
}
void OnDisable()
{
if (ARAnchorManager.instance is ARAnchorManager manager)
{
manager.TryRemoveAnchor(this);
}
}
}
}