XRReferenceObjectLibrary.cs
3.63 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System;
using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace UnityEngine.XR.ARSubsystems
{
/// <summary>
/// A container for reference objects. A reference object represents a 3D scan
/// of a real object that can be recognized in the environment. A <see cref="XRObjectTrackingSubsystem"/>
/// will search for objects based on the contents of a <see cref="XRReferenceObjectLibrary"/>.
/// </summary>
/// <seealso cref="XRReferenceObject"/>
/// <seealso cref="XRReferenceObjectEntry"/>
[CreateAssetMenu(fileName = "ReferenceObjectLibrary" , menuName = "XR/Reference Object Library", order = 3)]
[HelpURL(HelpUrls.Manual + "object-tracking.html")]
public class XRReferenceObjectLibrary : ScriptableObject
{
/// <summary>
/// The number of reference objects in the library.
/// </summary>
public int count { get { return m_ReferenceObjects.Count; } }
/// <summary>
/// Gets an enumerator which can be used to iterate over the reference objects in this library.
/// </summary>
/// <example>
/// This examples iterates over the reference objects contained in the library.
/// <code>
/// XRReferenceObjectLibrary library = ...
/// foreach (var referenceObject in library)
/// Debug.LogFormat("Reference object guid: {0}", referenceObject.guid);
/// </code>
/// </example>
/// <returns>An <c>IEnumerator</c> which can be used to iterate over the reference objects in the library.</returns>
public List<XRReferenceObject>.Enumerator GetEnumerator()
{
return m_ReferenceObjects.GetEnumerator();
}
/// <summary>
/// Get a reference object by index.
/// </summary>
/// <param name="index">The index in the array of reference objects.
/// Must be greater than or equal to 0 and less than <see cref="count"/>.</param>
/// <returns>The <see cref="XRReferenceObject"/> at <paramref name="index"/>.</returns>
public XRReferenceObject this[int index]
{
get
{
return m_ReferenceObjects[index];
}
}
/// <summary>
/// A <c>Guid</c> associated with this reference library.
/// The Guid is used to uniquely identify this library at runtime.
/// </summary>
public Guid guid
{
get { return GuidUtil.Compose(m_GuidLow, m_GuidHigh); }
}
/// <summary>
/// Get the index of <paramref name="referenceObject"/> in the object library.
/// </summary>
/// <param name="referenceObject">The <see cref="XRReferenceObject"/> to find.</param>
/// <returns>The zero-based index of the <paramref name="referenceObject"/>, or -1 if not found.</returns>
public int indexOf(XRReferenceObject referenceObject)
{
return m_ReferenceObjects.IndexOf(referenceObject);
}
#if UNITY_EDITOR
void Awake()
{
if ((m_GuidLow == 0) && (m_GuidHigh == 0))
{
var bytes = Guid.NewGuid().ToByteArray();
m_GuidLow = BitConverter.ToUInt64(bytes, 0);
m_GuidHigh = BitConverter.ToUInt64(bytes, 8);
EditorUtility.SetDirty(this);
}
}
#endif
#pragma warning disable CS0649
[SerializeField]
ulong m_GuidLow;
[SerializeField]
ulong m_GuidHigh;
#pragma warning restore CS0649
[SerializeField]
internal List<XRReferenceObject> m_ReferenceObjects = new List<XRReferenceObject>();
}
}