ARTrackable.cs
3.17 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
68
69
70
71
72
73
74
75
76
77
using System;
using UnityEngine.XR.ARSubsystems;
namespace UnityEngine.XR.ARFoundation
{
/// <summary>
/// A generic component for trackables. A "trackable" is a feature in the physical
/// environment that can be detected and tracked by an XR device.
/// </summary>
/// <typeparam name="TSessionRelativeData">The raw, session relative data type used to update this trackable.</typeparam>
/// <typeparam name="TTrackable">The concrete class which derives from <see cref="ARTrackable{TSessionRelativeData, TTrackable}"/>.</typeparam>
public class ARTrackable<TSessionRelativeData, TTrackable> : MonoBehaviour
where TSessionRelativeData : struct, ITrackable
where TTrackable : ARTrackable<TSessionRelativeData, TTrackable>
{
[SerializeField]
[Tooltip("If true, this component's GameObject will be removed immediately when this trackable is removed.")]
bool m_DestroyOnRemoval = true;
/// <summary>
/// If true, this component's <c>GameObject</c> will be removed immediately when the XR device reports this trackable is no longer tracked.
/// </summary>
/// <remarks>
/// Setting this to false will keep the <c>GameObject</c> around. You may want to do this, for example,
/// if you have custom removal logic, such as a fade out.
/// </remarks>
public bool destroyOnRemoval
{
get { return m_DestroyOnRemoval; }
set { m_DestroyOnRemoval = value; }
}
/// <summary>
/// The <c>TrackableId</c> associated with this trackable. <c>TrackableId</c>s
/// are typically unique to a particular session.
/// </summary>
public TrackableId trackableId
{
get { return sessionRelativeData.trackableId; }
}
/// <summary>
/// The tracking state associated with this trackable.
/// </summary>
public TrackingState trackingState
{
get { return sessionRelativeData.trackingState; }
}
/// <summary>
/// Pending means the trackable was added manually (usually via an <c>AddTrackable</c>-style method
/// on its manager) but has not yet been reported as added.
/// </summary>
public bool pending { get; internal set; }
/// <summary>
/// The session-relative data associated with this trackable.
/// </summary>
protected TSessionRelativeData sessionRelativeData { get; private set; }
/// <summary>
/// Invoked just after the session-relative data has been set.
/// The <c>GameObject</c>'s transform has already been updated.
/// You may override this method to perform further updates specific
/// to the derived trackable.
/// </summary>
protected internal virtual void OnAfterSetSessionRelativeData()
{ }
internal void SetSessionRelativeData(TSessionRelativeData sessionRelativeData)
{
this.sessionRelativeData = sessionRelativeData;
transform.localPosition = sessionRelativeData.pose.position;
transform.localRotation = sessionRelativeData.pose.rotation;
}
}
}