SW 중심대학 OSS GIT 서버 박건태, 이승준, 고기완, 이준호 새로운 배포
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
3.2 KiB

4 years ago
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace UnityEngine.XR.ARSubsystems
  4. {
  5. /// <summary>
  6. /// A session-unique identifier for trackables in the real-world environment, e.g., planes and feature points.
  7. /// </summary>
  8. /// <remarks>
  9. /// <para>
  10. /// Ids are generally unique to a particular session, but multiple sessions may produce
  11. /// identical ids for different trackables.
  12. /// </para><para>
  13. /// A trackable id is a 128 bit number, stored as two ulongs. This makes it large enough to hold a <c>Guid</c>.
  14. /// </para>
  15. /// </remarks>
  16. [StructLayout(LayoutKind.Sequential)]
  17. public struct TrackableId : IEquatable<TrackableId>
  18. {
  19. /// <summary>
  20. /// Get the invalid id.
  21. /// </summary>
  22. public static TrackableId invalidId { get { return s_InvalidId; } }
  23. /// <summary>
  24. /// The first half of the id.
  25. /// </summary>
  26. public ulong subId1
  27. {
  28. get { return m_SubId1; }
  29. set { m_SubId1 = value; }
  30. }
  31. /// <summary>
  32. /// The second half of the id.
  33. /// </summary>
  34. public ulong subId2
  35. {
  36. get { return m_SubId2; }
  37. set { m_SubId2 = value; }
  38. }
  39. /// <summary>
  40. /// Constructs a <c>TrackableId</c> from two <c>ulong</c>s.
  41. /// </summary>
  42. /// <param name="subId1">The first half of the id.</param>
  43. /// <param name="subId2">The second half of the id.</param>
  44. public TrackableId(ulong subId1, ulong subId2)
  45. {
  46. m_SubId1 = subId1;
  47. m_SubId2 = subId2;
  48. }
  49. /// <summary>
  50. /// Generates a string representation of the id suitable for debugging.
  51. /// </summary>
  52. /// <returns>A string representation of the id.</returns>
  53. public override string ToString()
  54. {
  55. return string.Format("{0}-{1}",
  56. m_SubId1.ToString("X16"),
  57. m_SubId2.ToString("X16"));
  58. }
  59. /// <summary>
  60. /// Generates a hash code suitable for use in a <c>Dictionary</c> or <c>Set</c>.
  61. /// </summary>
  62. /// <returns>A hash code for participation in certain collections.</returns>
  63. public override int GetHashCode()
  64. {
  65. unchecked
  66. {
  67. var hash = m_SubId1.GetHashCode();
  68. return hash * 486187739 + m_SubId2.GetHashCode();
  69. }
  70. }
  71. public override bool Equals(object obj)
  72. {
  73. return obj is TrackableId && Equals((TrackableId)obj);
  74. }
  75. public bool Equals(TrackableId other)
  76. {
  77. return (m_SubId1 == other.m_SubId1) && (m_SubId2 == other.m_SubId2);
  78. }
  79. public static bool operator==(TrackableId id1, TrackableId id2)
  80. {
  81. return
  82. (id1.m_SubId1 == id2.m_SubId1) &&
  83. (id1.m_SubId2 == id2.m_SubId2);
  84. }
  85. public static bool operator!=(TrackableId id1, TrackableId id2)
  86. {
  87. return
  88. (id1.m_SubId1 != id2.m_SubId1) ||
  89. (id1.m_SubId2 != id2.m_SubId2);
  90. }
  91. static TrackableId s_InvalidId = new TrackableId(0, 0);
  92. ulong m_SubId1;
  93. ulong m_SubId2;
  94. }
  95. }