ONSPSettings.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using UnityEngine;
  2. using System.Collections;
  3. #if UNITY_EDITOR
  4. [UnityEditor.InitializeOnLoad]
  5. #endif
  6. public sealed class ONSPSettings : ScriptableObject
  7. {
  8. [SerializeField]
  9. public int voiceLimit = 64;
  10. private static ONSPSettings instance;
  11. public static ONSPSettings Instance
  12. {
  13. get
  14. {
  15. if (instance == null)
  16. {
  17. instance = Resources.Load<ONSPSettings>("ONSPSettings");
  18. // This can happen if the developer never input their App Id into the Unity Editor
  19. // and therefore never created the OculusPlatformSettings.asset file
  20. // Use a dummy object with defaults for the getters so we don't have a null pointer exception
  21. if (instance == null)
  22. {
  23. instance = ScriptableObject.CreateInstance<ONSPSettings>();
  24. #if UNITY_EDITOR
  25. // Only in the editor should we save it to disk
  26. string properPath = System.IO.Path.Combine(UnityEngine.Application.dataPath, "Resources");
  27. if (!System.IO.Directory.Exists(properPath))
  28. {
  29. UnityEditor.AssetDatabase.CreateFolder("Assets", "Resources");
  30. }
  31. string fullPath = System.IO.Path.Combine(
  32. System.IO.Path.Combine("Assets", "Resources"),
  33. "ONSPSettings.asset");
  34. UnityEditor.AssetDatabase.CreateAsset(instance, fullPath);
  35. #endif
  36. }
  37. }
  38. return instance;
  39. }
  40. }
  41. }