using System;
using System.Collections;
using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace UnityEngine.XR.ARSubsystems
{
///
/// A container for reference objects. A reference object represents a 3D scan
/// of a real object that can be recognized in the environment. A
/// will search for objects based on the contents of a .
///
///
///
[CreateAssetMenu(fileName = "ReferenceObjectLibrary" , menuName = "XR/Reference Object Library", order = 3)]
[HelpURL("features/object-tracking")]
public class XRReferenceObjectLibrary : ScriptableObject, IEnumerable
{
///
/// The number of reference objects in the library.
///
public int count => m_ReferenceObjects.Count;
///
/// Gets an enumerator which can be used to iterate over the reference objects in this library.
///
///
/// This examples iterates over the reference objects contained in the library.
///
/// XRReferenceObjectLibrary library = ...
/// foreach (var referenceObject in library)
/// {
/// Debug.LogFormat("Reference object guid: {0}", referenceObject.guid);
/// }
///
///
/// Returns an enumerator which can be used to iterate over the reference objects in this library.
public List.Enumerator GetEnumerator() => m_ReferenceObjects.GetEnumerator();
///
/// Gets an enumerator which can be used to iterate over the reference objects in this library.
///
/// Returns an object which can be used to iterate over the reference objects in this library.
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
///
/// Gets an enumerator which can be used to iterate over the reference objects in this library.
///
/// Returns an object which can be used to iterate over the reference objects in this library.
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
///
/// Get a reference object by index.
///
/// The index in the array of reference objects.
/// Must be greater than or equal to 0 and less than .
/// The at .
public XRReferenceObject this[int index] => m_ReferenceObjects[index];
///
/// A GUID associated with this reference library.
/// The GUID is used to uniquely identify this library at runtime.
///
public Guid guid => GuidUtil.Compose(m_GuidLow, m_GuidHigh);
///
/// Get the index of in the object library.
///
/// The to find.
/// Returns the zero-based index of the if found. Returns -1 if not
/// found.
public int IndexOf(XRReferenceObject referenceObject) => m_ReferenceObjects.IndexOf(referenceObject);
///
/// Adds a new to this library.
///
/// The reference object to add.
public void Add(XRReferenceObject referenceObject)
{
referenceObject.OnAddToLibrary(this);
m_ReferenceObjects.Add(referenceObject);
#if UNITY_EDITOR
EditorUtility.SetDirty(this);
#endif
}
#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 m_ReferenceObjects = new List();
}
}