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.

239 lines
9.9 KiB

4 years ago
  1. using System;
  2. namespace UnityEngine.XR.ARSubsystems
  3. {
  4. /// <summary>
  5. /// This subsystem controls the lifecycle of an XR session. Some platforms,
  6. /// particularly those that have non-XR modes, need to be able to turn the
  7. /// session on and off to enter and exit XR mode(s) of operation.
  8. /// </summary>
  9. public abstract class XRSessionSubsystem : XRSubsystem<XRSessionSubsystemDescriptor>
  10. {
  11. /// <summary>
  12. /// Returns an implementation-defined pointer associated with the session.
  13. /// </summary>
  14. public IntPtr nativePtr => m_Provider.nativePtr;
  15. /// <summary>
  16. /// Returns a unique session identifier for this session.
  17. /// </summary>
  18. public Guid sessionId => m_Provider.sessionId;
  19. /// <summary>
  20. /// Asynchronously retrieves the <see cref="SessionAvailability"/>. Used to determine whether
  21. /// the current device supports XR and if the necessary software is installed.
  22. /// </summary>
  23. /// <remarks>
  24. /// This platform-agnostic method is typically implemented by a platform-specific package.
  25. /// </remarks>
  26. /// <returns>A <see cref="Promise{SessionAvailability}"/> which can be used to determine when the
  27. /// availability has been determined and retrieve the result.</returns>
  28. public Promise<SessionAvailability> GetAvailabilityAsync() => m_Provider.GetAvailabilityAsync();
  29. /// <summary>
  30. /// Asynchronously attempts to install XR software on the current device.
  31. /// Throws if <see cref="XRSessionSubsystemDescriptor.supportsInstall"/> is <c>false</c>.
  32. /// </summary>
  33. /// <remarks>
  34. /// This platform-agnostic method is typically implemented by a platform-specific package.
  35. /// </remarks>
  36. /// <returns>A <see cref="Promise{SessionInstallationStatus}"/> which can be used to determine when the
  37. /// installation completes and retrieve the result.</returns>
  38. public Promise<SessionInstallationStatus> InstallAsync()
  39. {
  40. if (!SubsystemDescriptor.supportsInstall)
  41. throw new NotSupportedException("InstallAsync is not supported on this platform.");
  42. return m_Provider.InstallAsync();
  43. }
  44. /// <summary>
  45. /// Do not call this directly. Call create on a valid <see cref="XRSessionSubsystemDescriptor"/> instead.
  46. /// </summary>
  47. public XRSessionSubsystem() => m_Provider = CreateProvider();
  48. /// <summary>
  49. /// Starts or resumes the session.
  50. /// </summary>
  51. protected sealed override void OnStart() => m_Provider.Resume();
  52. /// <summary>
  53. /// Restarts a session. <see cref="Stop"/> and <see cref="Start"/> pause and resume
  54. /// a session, respectively. <c>Restart</c> resets the session state and clears
  55. /// and any detected trackables.
  56. /// </summary>
  57. public void Reset() => m_Provider.Reset();
  58. /// <summary>
  59. /// Pauses the session.
  60. /// </summary>
  61. protected sealed override void OnStop() => m_Provider.Pause();
  62. /// <summary>
  63. /// Destroys the session.
  64. /// </summary>
  65. protected sealed override void OnDestroyed() => m_Provider.Destroy();
  66. /// <summary>
  67. /// Trigger the session's update loop.
  68. /// </summary>
  69. /// <param name="updateParams">Data needed by the session to perform its update.</param>
  70. public void Update(XRSessionUpdateParams updateParams) => m_Provider.Update(updateParams);
  71. /// <summary>
  72. /// Should be invoked when the application is paused.
  73. /// </summary>
  74. public void OnApplicationPause() => m_Provider.OnApplicationPause();
  75. /// <summary>
  76. /// Should be invoked when the application is resumed.
  77. /// </summary>
  78. public void OnApplicationResume() => m_Provider.OnApplicationResume();
  79. /// <summary>
  80. /// Gets the <see cref="TrackingState"/> for the session.
  81. /// </summary>
  82. public TrackingState trackingState => m_Provider.trackingState;
  83. /// <summary>
  84. /// Gets the <see cref="NotTrackingReason"/> for the session.
  85. /// </summary>
  86. public NotTrackingReason notTrackingReason => m_Provider.notTrackingReason;
  87. /// <summary>
  88. /// Whether the AR session update is synchronized with the Unity frame rate.
  89. /// If <c>true</c>, <see cref="Update"/> should block until the next AR frame is available.
  90. /// </summary>
  91. /// <exception cref="System.NotSupportedException">Thrown if <see cref="XRSessionSubsystemDescriptor.supportsMatchFrameRate"/> is <c>False</c>.</exception>
  92. public bool matchFrameRate
  93. {
  94. get => m_Provider.matchFrameRate;
  95. set => m_Provider.matchFrameRate = value;
  96. }
  97. /// <summary>
  98. /// The native update rate of the AR Session.
  99. /// </summary>
  100. /// <exception cref="System.NotSupportedException">Thrown if <see cref="XRSessionSubsystemDescriptor.supportsMatchFrameRate"/> is <c>False</c>.</exception>
  101. public int frameRate => m_Provider.frameRate;
  102. /// <summary>
  103. /// Implement this to provide this class with an interface to
  104. /// platform specific implementations.
  105. /// </summary>
  106. /// <returns>An implementation specific provider.</returns>
  107. protected abstract Provider CreateProvider();
  108. /// <summary>
  109. /// The API this subsystem uses to interop with
  110. /// different provider implementations.
  111. /// </summary>
  112. protected class Provider
  113. {
  114. /// <summary>
  115. /// Invoked to start or resume a session. This is different from <see cref="OnApplicationResume"/>.
  116. /// </summary>
  117. public virtual void Resume() { }
  118. /// <summary>
  119. /// Invoked to pause a running session. This is different from <see cref="OnApplicationPause"/>.
  120. /// </summary>
  121. public virtual void Pause() { }
  122. /// <summary>
  123. /// Perform any per-frame update logic here.
  124. /// </summary>
  125. /// <param name="updateParams">Paramters about the current state that may be needed to inform the session.</param>
  126. public virtual void Update(XRSessionUpdateParams updateParams) { }
  127. /// <summary>
  128. /// Stop the session and destroy all associated resources.
  129. /// </summary>
  130. public virtual void Destroy() { }
  131. /// <summary>
  132. /// Reset the session. The behavior should be equivalent to destroying and recreating the session.
  133. /// </summary>
  134. public virtual void Reset() { }
  135. /// <summary>
  136. /// Invoked when the application is paused.
  137. /// </summary>
  138. public virtual void OnApplicationPause() { }
  139. /// <summary>
  140. /// Invoked when the application is resumed.
  141. /// </summary>
  142. public virtual void OnApplicationResume() { }
  143. /// <summary>
  144. /// Get a pointer to an object associated with the session.
  145. /// Callers should be able to manipulate the session in their own code using this.
  146. /// </summary>
  147. public virtual IntPtr nativePtr => IntPtr.Zero;
  148. /// <summary>
  149. /// Get the session's availability, such as whether the platform supports XR.
  150. /// </summary>
  151. /// <returns>A <see cref="Promise{T}"/> that the caller can yield on until availability is determined.</returns>
  152. public virtual Promise<SessionAvailability> GetAvailabilityAsync()
  153. {
  154. return Promise<SessionAvailability>.CreateResolvedPromise(SessionAvailability.None);
  155. }
  156. /// <summary>
  157. /// Attempt to update or install necessary XR software. Will only be called if
  158. /// <see cref="XRSessionSubsystemDescriptor.supportsInstall"/> is true.
  159. /// </summary>
  160. /// <returns></returns>
  161. public virtual Promise<SessionInstallationStatus> InstallAsync()
  162. {
  163. return Promise<SessionInstallationStatus>.CreateResolvedPromise(SessionInstallationStatus.ErrorInstallNotSupported);
  164. }
  165. /// <summary>
  166. /// Get the <see cref="TrackingState"/> for the session.
  167. /// </summary>
  168. public virtual TrackingState trackingState => TrackingState.None;
  169. /// <summary>
  170. /// Get the <see cref="NotTrackingReason"/> for the session.
  171. /// </summary>
  172. public virtual NotTrackingReason notTrackingReason => NotTrackingReason.Unsupported;
  173. /// <summary>
  174. /// Get a unique identifier for this session
  175. /// </summary>
  176. public virtual Guid sessionId => Guid.Empty;
  177. /// <summary>
  178. /// Whether the AR session update is synchronized with the Unity frame rate.
  179. /// If <c>true</c>, <see cref="Update"/> should block until the next AR frame is available.
  180. /// Must be implemented if
  181. /// <see cref="XRSessionSubsystemDescriptor.supportsMatchFrameRate"/>
  182. /// is <c>True</c>.
  183. /// </summary>
  184. public virtual bool matchFrameRate
  185. {
  186. get => false;
  187. set
  188. {
  189. if (value)
  190. {
  191. throw new NotSupportedException("Matching frame rate is not supported.");
  192. }
  193. }
  194. }
  195. /// <summary>
  196. /// The native update rate of the AR Session. Must be implemented if
  197. /// <see cref="XRSessionSubsystemDescriptor.supportsMatchFrameRate"/>
  198. /// is <c>True</c>.
  199. /// </summary>
  200. public virtual int frameRate =>
  201. throw new NotSupportedException("Querying the frame rate is not supported by this session subsystem.");
  202. }
  203. Provider m_Provider;
  204. }
  205. }