TrackableId.cs
3.34 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
101
102
103
104
105
106
107
108
using System;
using System.Runtime.InteropServices;
namespace UnityEngine.XR.ARSubsystems
{
/// <summary>
/// A session-unique identifier for trackables in the real-world environment, e.g., planes and feature points.
/// </summary>
/// <remarks>
/// <para>
/// Ids are generally unique to a particular session, but multiple sessions may produce
/// identical ids for different trackables.
/// </para><para>
/// A trackable id is a 128 bit number, stored as two ulongs. This makes it large enough to hold a <c>Guid</c>.
/// </para>
/// </remarks>
[StructLayout(LayoutKind.Sequential)]
public struct TrackableId : IEquatable<TrackableId>
{
/// <summary>
/// Get the invalid id.
/// </summary>
public static TrackableId invalidId { get { return s_InvalidId; } }
/// <summary>
/// The first half of the id.
/// </summary>
public ulong subId1
{
get { return m_SubId1; }
set { m_SubId1 = value; }
}
/// <summary>
/// The second half of the id.
/// </summary>
public ulong subId2
{
get { return m_SubId2; }
set { m_SubId2 = value; }
}
/// <summary>
/// Constructs a <c>TrackableId</c> from two <c>ulong</c>s.
/// </summary>
/// <param name="subId1">The first half of the id.</param>
/// <param name="subId2">The second half of the id.</param>
public TrackableId(ulong subId1, ulong subId2)
{
m_SubId1 = subId1;
m_SubId2 = subId2;
}
/// <summary>
/// Generates a string representation of the id suitable for debugging.
/// </summary>
/// <returns>A string representation of the id.</returns>
public override string ToString()
{
return string.Format("{0}-{1}",
m_SubId1.ToString("X16"),
m_SubId2.ToString("X16"));
}
/// <summary>
/// Generates a hash code suitable for use in a <c>Dictionary</c> or <c>Set</c>.
/// </summary>
/// <returns>A hash code for participation in certain collections.</returns>
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;
}
}