using System;
using System.Runtime.InteropServices;
namespace UnityEngine.XR.ARSubsystems
{
///
/// A session-unique identifier for trackables in the real-world environment, e.g., planes and feature points.
///
///
///
/// Ids are generally unique to a particular session, but multiple sessions may produce
/// identical ids for different trackables.
///
/// A trackable id is a 128 bit number, stored as two ulongs. This makes it large enough to hold a Guid.
///
///
[StructLayout(LayoutKind.Sequential)]
public struct TrackableId : IEquatable
{
///
/// Get the invalid id.
///
public static TrackableId invalidId { get { return s_InvalidId; } }
///
/// The first half of the id.
///
public ulong subId1
{
get { return m_SubId1; }
set { m_SubId1 = value; }
}
///
/// The second half of the id.
///
public ulong subId2
{
get { return m_SubId2; }
set { m_SubId2 = value; }
}
///
/// Constructs a TrackableId from two ulongs.
///
/// The first half of the id.
/// The second half of the id.
public TrackableId(ulong subId1, ulong subId2)
{
m_SubId1 = subId1;
m_SubId2 = subId2;
}
///
/// Generates a string representation of the id suitable for debugging.
///
/// A string representation of the id.
public override string ToString()
{
return string.Format("{0}-{1}",
m_SubId1.ToString("X16"),
m_SubId2.ToString("X16"));
}
///
/// Generates a hash code suitable for use in a Dictionary or Set.
///
/// A hash code for participation in certain collections.
public override int GetHashCode()
{
unchecked
{
var hash = m_SubId1.GetHashCode();
return hash * 486187739 + m_SubId2.GetHashCode();
}
}
public override bool Equals(object obj)
{
return obj is TrackableId && Equals((TrackableId)obj);
}
public bool Equals(TrackableId other)
{
return (m_SubId1 == other.m_SubId1) && (m_SubId2 == other.m_SubId2);
}
public static bool operator==(TrackableId id1, TrackableId id2)
{
return
(id1.m_SubId1 == id2.m_SubId1) &&
(id1.m_SubId2 == id2.m_SubId2);
}
public static bool operator!=(TrackableId id1, TrackableId id2)
{
return
(id1.m_SubId1 != id2.m_SubId1) ||
(id1.m_SubId2 != id2.m_SubId2);
}
static TrackableId s_InvalidId = new TrackableId(0, 0);
ulong m_SubId1;
ulong m_SubId2;
}
}