Assignment for RMIT Mixed Reality in 2020
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.

84 lines
2.2 KiB

  1. namespace Oculus.Platform
  2. {
  3. using UnityEngine;
  4. using System.Collections;
  5. #if UNITY_EDITOR
  6. [UnityEditor.InitializeOnLoad]
  7. #endif
  8. public sealed class PlatformSettings : ScriptableObject
  9. {
  10. public static string AppID
  11. {
  12. get { return Instance.ovrAppID; }
  13. set { Instance.ovrAppID = value; }
  14. }
  15. public static string MobileAppID
  16. {
  17. get { return Instance.ovrMobileAppID; }
  18. set { Instance.ovrMobileAppID = value; }
  19. }
  20. public static bool UseStandalonePlatform
  21. {
  22. get { return Instance.ovrUseStandalonePlatform; }
  23. set { Instance.ovrUseStandalonePlatform = value; }
  24. }
  25. [SerializeField]
  26. private string ovrAppID = "";
  27. [SerializeField]
  28. private string ovrMobileAppID = "";
  29. #if UNITY_EDITOR_WIN
  30. [SerializeField]
  31. private bool ovrUseStandalonePlatform = false;
  32. #else
  33. [SerializeField]
  34. private bool ovrUseStandalonePlatform = true;
  35. #endif
  36. private static PlatformSettings instance;
  37. public static PlatformSettings Instance
  38. {
  39. get
  40. {
  41. if (instance == null)
  42. {
  43. instance = Resources.Load<PlatformSettings>("OculusPlatformSettings");
  44. // This can happen if the developer never input their App Id into the Unity Editor
  45. // and therefore never created the OculusPlatformSettings.asset file
  46. // Use a dummy object with defaults for the getters so we don't have a null pointer exception
  47. if (instance == null)
  48. {
  49. instance = ScriptableObject.CreateInstance<PlatformSettings>();
  50. #if UNITY_EDITOR
  51. // Only in the editor should we save it to disk
  52. string properPath = System.IO.Path.Combine(UnityEngine.Application.dataPath, "Resources");
  53. if (!System.IO.Directory.Exists(properPath))
  54. {
  55. UnityEditor.AssetDatabase.CreateFolder("Assets", "Resources");
  56. }
  57. string fullPath = System.IO.Path.Combine(
  58. System.IO.Path.Combine("Assets", "Resources"),
  59. "OculusPlatformSettings.asset"
  60. );
  61. UnityEditor.AssetDatabase.CreateAsset(instance, fullPath);
  62. #endif
  63. }
  64. }
  65. return instance;
  66. }
  67. set
  68. {
  69. instance = value;
  70. }
  71. }
  72. }
  73. }