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.

138 lines
5.8 KiB

4 years ago
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace UnityEngine.XR.ARSubsystems
  4. {
  5. /// <summary>
  6. /// The session-relative data associated with a participant.
  7. /// </summary>
  8. /// <remarks>
  9. /// A "participant" is another device in a multi-user collaborative session.
  10. /// </remarks>
  11. /// <seealso cref="XRParticipantSubsystem"/>
  12. [StructLayout(LayoutKind.Sequential)]
  13. public struct XRParticipant : ITrackable, IEquatable<XRParticipant>
  14. {
  15. TrackableId m_TrackableId;
  16. Pose m_Pose;
  17. TrackingState m_TrackingState;
  18. IntPtr m_NativePtr;
  19. Guid m_SessionId;
  20. /// <summary>
  21. /// Constructs an <see cref="XRParticipant"/>. <see cref="XRParticipant"/>s are generated
  22. /// by <see cref="XRParticipantSubsystem.GetChanges(Unity.Collections.Allocator)"/>.
  23. /// </summary>
  24. /// <param name="trackableId">The <see cref="TrackableId"/> associated with this participant.</param>
  25. /// <param name="pose">The <c>Pose</c> associated with this participant.</param>
  26. /// <param name="trackingState">The <see cref="TrackingState"/> associated with this participant.</param>
  27. /// <param name="nativePtr">A native pointer associated with this participant.</param>
  28. /// <param name="sessionId">The session from which this participant originated.</param>
  29. public XRParticipant(
  30. TrackableId trackableId,
  31. Pose pose,
  32. TrackingState trackingState,
  33. IntPtr nativePtr,
  34. Guid sessionId)
  35. {
  36. m_TrackableId = trackableId;
  37. m_Pose = pose;
  38. m_TrackingState = trackingState;
  39. m_NativePtr = nativePtr;
  40. m_SessionId = sessionId;
  41. }
  42. /// <summary>
  43. /// An <see cref="XRParticipant"/> with default values. This is mostly zero-initialized,
  44. /// except for objects like <c>Pose</c>s, which are initialized to <c>Pose.identity</c>.
  45. /// </summary>
  46. public static XRParticipant defaultParticipant => k_Default;
  47. /// <summary>
  48. /// The <see cref="TrackableId"/> associated with this participant.
  49. /// </summary>
  50. public TrackableId trackableId => m_TrackableId;
  51. /// <summary>
  52. /// The <c>Pose</c>, in session-space, associated with this participant.
  53. /// </summary>
  54. public Pose pose => m_Pose;
  55. /// <summary>
  56. /// The <see cref="TrackingState"/> associated with this participant.
  57. /// </summary>
  58. public TrackingState trackingState => m_TrackingState;
  59. /// <summary>
  60. /// A native pointer associated with this participant.
  61. /// The data pointer to by this pointer is implementation defined.
  62. /// </summary>
  63. public IntPtr nativePtr => m_NativePtr;
  64. /// <summary>
  65. /// This participant's session identifier.
  66. /// </summary>
  67. public Guid sessionId => m_SessionId;
  68. static readonly XRParticipant k_Default = new XRParticipant
  69. {
  70. m_TrackableId = TrackableId.invalidId,
  71. m_Pose = Pose.identity,
  72. m_NativePtr = IntPtr.Zero
  73. };
  74. /// <summary>
  75. /// Generates a hash suitable for use with containers like <c>HashSet</c> and <c>Dictionary</c>.
  76. /// </summary>
  77. /// <returns>A hash suitable for use with containers like <c>HashSet</c> and <c>Dictionary</c>.</returns>
  78. public override int GetHashCode()
  79. {
  80. unchecked
  81. {
  82. int hash = m_TrackableId.GetHashCode();
  83. hash = hash * 486187739 + m_Pose.GetHashCode();
  84. hash = hash * 486187739 + ((int)m_TrackingState).GetHashCode();
  85. hash = hash * 486187739 + m_NativePtr.GetHashCode();
  86. return hash;
  87. }
  88. }
  89. /// <summary>
  90. /// Tests for equality.
  91. /// </summary>
  92. /// <param name="other">The other <see cref="XRParticipant"/> to compare against.</param>
  93. /// <returns><c>true</c> if <paramref name="other"/> is equal to this <see cref="XRParticipant"/>.</returns>
  94. public bool Equals(XRParticipant other)
  95. {
  96. return
  97. m_TrackableId.Equals(other.m_TrackableId) &&
  98. m_Pose.Equals(other.m_Pose) &&
  99. (m_TrackingState == other.m_TrackingState) &&
  100. (m_NativePtr == other.m_NativePtr);
  101. }
  102. /// <summary>
  103. /// Tests for equality.
  104. /// </summary>
  105. /// <param name="obj">The <c>object</c> to compare against.</param>
  106. /// <returns><c>true</c> if <paramref name="obj"/> is of type <see cref="XRParticipant"/> and <see cref="Equals(XRParticipant)"/>
  107. /// also returns <c>true</c>.</returns>
  108. public override bool Equals(object obj) => (obj is XRParticipant) && Equals((XRParticipant)obj);
  109. /// <summary>
  110. /// Tests for equality. Same as <see cref="Equals(XRParticipant)"/>.
  111. /// </summary>
  112. /// <param name="lhs">The left-hand side of the comparison.</param>
  113. /// <param name="rhs">The right-hand side of the comparison.</param>
  114. /// <returns><c>true</c> if <paramref name="lhs"/> is equal to <paramref name="rhs"/>.</returns>
  115. public static bool operator ==(XRParticipant lhs, XRParticipant rhs) => lhs.Equals(rhs);
  116. /// <summary>
  117. /// Tests for inequality. Same as <c>!</c><see cref="Equals(XRParticipant)"/>.
  118. /// </summary>
  119. /// <param name="lhs">The left-hand side of the comparison.</param>
  120. /// <param name="rhs">The right-hand side of the comparison.</param>
  121. /// <returns><c>true</c> if <paramref name="lhs"/> is not equal to <paramref name="rhs"/>.</returns>
  122. public static bool operator !=(XRParticipant lhs, XRParticipant rhs) => !lhs.Equals(rhs);
  123. }
  124. }