SampleLoader.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using System.Collections.Generic;
  2. using UnityEngine.XR;
  3. using UnityEngine.XR.Management;
  4. #if UNITY_EDITOR
  5. using UnityEditor;
  6. using UnityEditor.XR.Management;
  7. #endif
  8. namespace Samples
  9. {
  10. /// <summary>
  11. /// Sample loader implentation showing how to create simple loader.
  12. /// NOTE: You have to rename this class to make it appear in the loader list for
  13. /// XRManager.
  14. /// </summary>
  15. #if UNITY_EDITOR
  16. [XRSupportedBuildTarget(BuildTargetGroup.Standalone, new BuildTarget[]{ BuildTarget.StandaloneWindows, BuildTarget.StandaloneWindows64})]
  17. [XRSupportedBuildTarget(BuildTargetGroup.Android)]
  18. #endif
  19. public class SampleLoader : XRLoaderHelper
  20. {
  21. static List<XRInputSubsystemDescriptor> s_InputSubsystemDescriptors =
  22. new List<XRInputSubsystemDescriptor>();
  23. /// <summary>Return the currently active Input Subsystem intance, if any.</summary>
  24. public XRInputSubsystem inputSubsystem
  25. {
  26. get { return GetLoadedSubsystem<XRInputSubsystem>(); }
  27. }
  28. SampleSettings GetSettings()
  29. {
  30. SampleSettings settings = null;
  31. // When running in the Unity Editor, we have to load user's customization of configuration data directly from
  32. // EditorBuildSettings. At runtime, we need to grab it from the static instance field instead.
  33. #if UNITY_EDITOR
  34. UnityEditor.EditorBuildSettings.TryGetConfigObject(SampleConstants.k_SettingsKey, out settings);
  35. #else
  36. settings = SampleSettings.s_RuntimeInstance;
  37. #endif
  38. return settings;
  39. }
  40. #region XRLoader API Implementation
  41. /// <summary>Implementaion of <see cref="XRLoader.Initialize"/></summary>
  42. /// <returns>True if successful, false otherwise</returns>
  43. public override bool Initialize()
  44. {
  45. SampleSettings settings = GetSettings();
  46. if (settings != null)
  47. {
  48. // TODO: Pass settings off to plugin prior to subsystem init.
  49. }
  50. CreateSubsystem<XRInputSubsystemDescriptor, XRInputSubsystem>(s_InputSubsystemDescriptors, "InputSubsystemDescriptor");
  51. return false;
  52. }
  53. /// <summary>Implementaion of <see cref="XRLoader.Start"/></summary>
  54. /// <returns>True if successful, false otherwise</returns>
  55. public override bool Start()
  56. {
  57. StartSubsystem<XRInputSubsystem>();
  58. return true;
  59. }
  60. /// <summary>Implementaion of <see cref="XRLoader.Stop"/></summary>
  61. /// <returns>True if successful, false otherwise</returns>
  62. public override bool Stop()
  63. {
  64. StopSubsystem<XRInputSubsystem>();
  65. return true;
  66. }
  67. /// <summary>Implementaion of <see cref="XRLoader.Deinitialize"/></summary>
  68. /// <returns>True if successful, false otherwise</returns>
  69. public override bool Deinitialize()
  70. {
  71. DestroySubsystem<XRInputSubsystem>();
  72. return base.Deinitialize();
  73. }
  74. #endregion
  75. }
  76. }