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.

180 lines
10 KiB

4 years ago
  1. using System;
  2. using Unity.Collections;
  3. namespace UnityEngine.XR.ARSubsystems
  4. {
  5. /// <summary>
  6. /// Base class for a reference point subsystem.
  7. /// </summary>
  8. /// <remarks>
  9. /// <para>A reference point is a pose in the physical environment that is tracked by an XR device.
  10. /// As the device refines its understanding of the environment, reference points will be
  11. /// updated, allowing developers to keep virtual content connected to a real-world position and orientation.</para>
  12. /// <para>This abstract class should be implemented by an XR provider and instantiated using the <c>SubsystemManager</c>
  13. /// to enumerate the available <see cref="XRReferencePointSubsystemDescriptor"/>s.</para>
  14. /// </remarks>
  15. [Obsolete("XRReferencePointSubsystem has been deprecated. Use XRAnchorSubsystem instead (UnityUpgradable) -> UnityEngine.XR.ARSubsystems.XRAnchorSubsystem", true)]
  16. public abstract class XRReferencePointSubsystem
  17. : TrackingSubsystem<XRReferencePoint, XRReferencePointSubsystemDescriptor>
  18. {
  19. /// <summary>
  20. /// Constructor. Do not invoke directly; use the <c>SubsystemManager</c>
  21. /// to enumerate the available <see cref="XRReferencePointSubsystemDescriptor"/>s
  22. /// and call <c>Create</c> on the desired descriptor.
  23. /// </summary>
  24. public XRReferencePointSubsystem() => m_Provider = CreateProvider();
  25. /// <summary>
  26. /// Starts the subsystem.
  27. /// </summary>
  28. protected sealed override void OnStart() => m_Provider.Start();
  29. /// <summary>
  30. /// Stops the subsystem.
  31. /// </summary>
  32. protected sealed override void OnStop() => m_Provider.Stop();
  33. /// <summary>
  34. /// Destroys the subsystem.
  35. /// </summary>
  36. protected sealed override void OnDestroyed() => m_Provider.Destroy();
  37. /// <summary>
  38. /// Get the changes (added, updated, & removed) reference points since the last call
  39. /// to <see cref="GetChanges(Allocator)"/>.
  40. /// </summary>
  41. /// <param name="allocator">An allocator to use for the <c>NativeArray</c>s in <see cref="TrackableChanges{T}"/>.</param>
  42. /// <returns>Changes since the last call to <see cref="GetChanges"/>.</returns>
  43. public override TrackableChanges<XRReferencePoint> GetChanges(Allocator allocator)
  44. {
  45. if (!running)
  46. throw new InvalidOperationException("Can't call \"GetChanges\" without \"Start\"ing the reference-point subsystem!");
  47. var changes = m_Provider.GetChanges(XRReferencePoint.defaultValue, allocator);
  48. #if DEVELOPMENT_BUILD || UNITY_EDITOR
  49. m_ValidationUtility.ValidateAndDisposeIfThrown(changes);
  50. #endif
  51. return changes;
  52. }
  53. /// <summary>
  54. /// Attempts to create a new reference point with the provide <paramref name="pose"/>.
  55. /// </summary>
  56. /// <param name="pose">The pose, in session space, of the new reference point.</param>
  57. /// <param name="referencePoint">The new reference point. Only valid if this method returns <c>true</c>.</param>
  58. /// <returns><c>true</c> if the new reference point was added, otherwise <c>false</c>.</returns>
  59. [Obsolete("XRReferencePointSubsystem.TryAddReferencePoint() has been deprecated. Use XRAnchorSubsystem.TryAddAnchor() instead (UnityUpgradable) -> UnityEngine.XR.ARSubsystems.XRAnchorSubsystem.TryAddAnchor(Pose, XRAnchor)", true)]
  60. public bool TryAddReferencePoint(Pose pose, out XRReferencePoint referencePoint)
  61. {
  62. return m_Provider.TryAddReferencePoint(pose, out referencePoint);
  63. }
  64. /// <summary>
  65. /// Attempts to create a new reference "attached" to the trackable with id <paramref name="trackableToAffix"/>.
  66. /// The behavior of the reference point depends on the type of trackable to which this reference point is attached.
  67. /// </summary>
  68. /// <param name="trackableToAffix">The id of the trackable to which to attach.</param>
  69. /// <param name="pose">The pose, in session space, of the reference point to create.</param>
  70. /// <param name="referencePoint">The new reference point. Only valid if this method returns <c>true</c>.</param>
  71. /// <returns><c>true</c> if the new reference point was added, otherwise <c>false</c>.</returns>
  72. [Obsolete("XRReferencePointSubsystem.TryAttachReferencePoint() has been deprecated. Use XRAnchorSubsystem.TryAttachAnchor() instead (UnityUpgradable) -> UnityEngine.XR.ARSubsystems.XRAnchorSubsystem.TryAttachAnchor(TrackableId, Pose, XRAnchor)", true)]
  73. public bool TryAttachReferencePoint(TrackableId trackableToAffix, Pose pose, out XRReferencePoint referencePoint)
  74. {
  75. return m_Provider.TryAttachReferencePoint(trackableToAffix, pose, out referencePoint);
  76. }
  77. /// <summary>
  78. /// Attempts to remove an existing reference point with <see cref="TrackableId"/> <paramref name="referencePointId"/>.
  79. /// </summary>
  80. /// <param name="referencePointId">The id of an existing reference point to remove.</param>
  81. /// <returns><c>true</c> if the reference point was removed, otherwise <c>false</c>.</returns>
  82. [Obsolete("XRReferencePointSubsystem.TryRemoveReferencePoint() has been deprecated. Use XRAnchorSubsystem.TryRemoveAnchor() instead (UnityUpgradable) -> UnityEngine.XR.ARSubsystems.XRAnchorSubsystem.TryRemoveAnchor(*)", true)]
  83. public bool TryRemoveReferencePoint(TrackableId referencePointId)
  84. {
  85. return m_Provider.TryRemoveReferencePoint(referencePointId);
  86. }
  87. /// <summary>
  88. /// An interface to be implemented by providers of this subsystem.
  89. /// </summary>
  90. protected abstract class Provider
  91. {
  92. /// <summary>
  93. /// Invoked when <c>Start</c> is called on the subsystem. This method is only called if the subsystem was not previously running.
  94. /// </summary>
  95. public virtual void Start() { }
  96. /// <summary>
  97. /// Invoked when <c>Stop</c> is called on the subsystem. This method is only called if the subsystem was previously running.
  98. /// </summary>
  99. public virtual void Stop() { }
  100. /// <summary>
  101. /// Called when <c>Destroy</c> is called on the subsystem.
  102. /// </summary>
  103. public virtual void Destroy() { }
  104. /// <summary>
  105. /// Invoked to get the changes to reference points (added, updated, & removed) since the last call to <see cref="GetChanges(Allocator)"/>.
  106. /// </summary>
  107. /// <param name="defaultReferencePoint">The default reference point. This should be used to initialize the returned
  108. /// <c>NativeArray</c>s for backwards compatibility.
  109. /// See <see cref="TrackableChanges{T}.TrackableChanges(void*, int, void*, int, void*, int, T, int, Allocator)"/>.
  110. /// </param>
  111. /// <param name="allocator">An allocator to use for the <c>NativeArray</c>s in <see cref="TrackableChanges{T}"/>.</param>
  112. /// <returns>Changes since the last call to <see cref="GetChanges"/>.</returns>
  113. public abstract TrackableChanges<XRReferencePoint> GetChanges(XRReferencePoint defaultReferencePoint, Allocator allocator);
  114. /// <summary>
  115. /// Should create a new reference point with the provide <paramref name="pose"/>.
  116. /// </summary>
  117. /// <param name="pose">The pose, in session space, of the new reference point.</param>
  118. /// <param name="referencePoint">The new reference point. Must be valid only if this method returns <c>true</c>.</param>
  119. /// <returns>Should return <c>true</c> if the new reference point was added, otherwise <c>false</c>.</returns>
  120. public virtual bool TryAddReferencePoint(Pose pose, out XRReferencePoint referencePoint)
  121. {
  122. referencePoint = default(XRReferencePoint);
  123. return false;
  124. }
  125. /// <summary>
  126. /// Should create a new reference "attached" to the trackable with id <paramref name="trackableToAffix"/>.
  127. /// The behavior of the reference point depends on the type of trackable to which this reference point is attached and
  128. /// may be implemenation-defined.
  129. /// </summary>
  130. /// <param name="trackableToAffix">The id of the trackable to which to attach.</param>
  131. /// <param name="pose">The pose, in session space, of the reference point to create.</param>
  132. /// <param name="referencePoint">The new reference point. Must be valid only if this method returns <c>true</c>.</param>
  133. /// <returns><c>true</c> if the new reference point was added, otherwise <c>false</c>.</returns>
  134. public virtual bool TryAttachReferencePoint(
  135. TrackableId trackableToAffix,
  136. Pose pose,
  137. out XRReferencePoint referencePoint)
  138. {
  139. referencePoint = default(XRReferencePoint);
  140. return false;
  141. }
  142. /// <summary>
  143. /// Should remove an existing reference point with <see cref="TrackableId"/> <paramref name="referencePointId"/>.
  144. /// </summary>
  145. /// <param name="referencePointId">The id of an existing reference point to remove.</param>
  146. /// <returns>Should return <c>true</c> if the reference point was removed, otherwise <c>false</c>. If the reference
  147. /// point does not exist, return <c>false</c>.</returns>
  148. public virtual bool TryRemoveReferencePoint(TrackableId referencePointId) => false;
  149. }
  150. /// <summary>
  151. /// Should return an instance of <see cref="IProvider"/>.
  152. /// </summary>
  153. /// <returns>The interface to the implementation-specific provider.</returns>
  154. protected abstract Provider CreateProvider();
  155. Provider m_Provider;
  156. #if DEVELOPMENT_BUILD || UNITY_EDITOR
  157. ValidationUtility<XRReferencePoint> m_ValidationUtility =
  158. new ValidationUtility<XRReferencePoint>();
  159. #endif
  160. }
  161. }