StandaloneLoader.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System.Collections.Generic;
  2. namespace UnityEngine.XR.Management.Tests.Standalone
  3. {
  4. public class StandaloneLoader : XRLoaderHelper
  5. {
  6. static List<StandaloneSubsystemDescriptor> s_StandaloneSubsystemDescriptors = new List<StandaloneSubsystemDescriptor>();
  7. public StandaloneSubsystem standaloneSubsystem
  8. {
  9. get
  10. {
  11. return GetLoadedSubsystem<StandaloneSubsystem>();
  12. }
  13. }
  14. public bool started { get; protected set; }
  15. public bool stopped { get; protected set; }
  16. public bool deInitialized { get; protected set; }
  17. void OnStartCalled()
  18. {
  19. started = true;
  20. }
  21. void OnStopCalled()
  22. {
  23. stopped = true;
  24. }
  25. void OnDestroyCalled()
  26. {
  27. deInitialized = true;
  28. }
  29. public override bool Initialize()
  30. {
  31. started = false;
  32. stopped = false;
  33. deInitialized = false;
  34. CreateSubsystem<StandaloneSubsystemDescriptor, StandaloneSubsystem>(s_StandaloneSubsystemDescriptors, "Standalone Subsystem");
  35. if (standaloneSubsystem == null)
  36. return false;
  37. standaloneSubsystem.startCalled += OnStartCalled;
  38. standaloneSubsystem.stopCalled += OnStopCalled;
  39. standaloneSubsystem.destroyCalled += OnDestroyCalled;
  40. return true;
  41. }
  42. public override bool Start()
  43. {
  44. if (standaloneSubsystem != null)
  45. StartSubsystem<StandaloneSubsystem>();
  46. return true;
  47. }
  48. public override bool Stop()
  49. {
  50. if (standaloneSubsystem != null)
  51. StopSubsystem<StandaloneSubsystem>();
  52. return true;
  53. }
  54. public override bool Deinitialize()
  55. {
  56. DestroySubsystem<StandaloneSubsystem>();
  57. if (standaloneSubsystem != null)
  58. {
  59. standaloneSubsystem.startCalled -= OnStartCalled;
  60. standaloneSubsystem.stopCalled -= OnStopCalled;
  61. standaloneSubsystem.destroyCalled -= OnDestroyCalled;
  62. }
  63. return base.Deinitialize();
  64. }
  65. }
  66. }