RenderStreamingProjectSettings.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System.IO;
  2. using UnityEditorInternal;
  3. using UnityEngine;
  4. namespace Unity.RenderStreaming.Editor
  5. {
  6. internal class RenderStreamingProjectSettings : ScriptableObject
  7. {
  8. const string filePath = "ProjectSettings/RenderStreamingProjectSettings.asset";
  9. [SerializeField] private bool m_WizardPopupAtStart = true;
  10. [SerializeField] private bool m_WizardPopupAlreadyShownOnce = false;
  11. public static bool wizardIsStartPopup
  12. {
  13. get => instance.m_WizardPopupAtStart;
  14. set
  15. {
  16. instance.m_WizardPopupAtStart = value;
  17. Save();
  18. }
  19. }
  20. public static bool wizardPopupAlreadyShownOnce
  21. {
  22. get => instance.m_WizardPopupAlreadyShownOnce;
  23. set
  24. {
  25. instance.m_WizardPopupAlreadyShownOnce = value;
  26. Save();
  27. }
  28. }
  29. static RenderStreamingProjectSettings s_Instance;
  30. static RenderStreamingProjectSettings instance => s_Instance ? s_Instance : CreateOrLoad();
  31. RenderStreamingProjectSettings()
  32. {
  33. s_Instance = this;
  34. }
  35. static RenderStreamingProjectSettings CreateOrLoad()
  36. {
  37. // Object loaded and created from this method.
  38. // So RenderStreamingProjectSettings constructor is called implicitly.
  39. // If RenderStreamingProjectSettings could be loaded, then s_Instance is assigned the loaded instance.
  40. InternalEditorUtility.LoadSerializedFileAndForget(filePath);
  41. if (s_Instance == null)
  42. {
  43. var created = CreateInstance<RenderStreamingProjectSettings>();
  44. created.hideFlags = HideFlags.HideAndDontSave;
  45. }
  46. System.Diagnostics.Debug.Assert(s_Instance != null);
  47. return s_Instance;
  48. }
  49. static void Save()
  50. {
  51. if (s_Instance == null)
  52. {
  53. Debug.Log("Cannot save ScriptableSingleton: no instance!");
  54. return;
  55. }
  56. string folderPath = Path.GetDirectoryName(filePath);
  57. if (!Directory.Exists(folderPath))
  58. {
  59. Directory.CreateDirectory(folderPath);
  60. }
  61. InternalEditorUtility.SaveToSerializedFileAndForget(new Object[] {s_Instance}, filePath,
  62. allowTextSerialization: true);
  63. }
  64. }
  65. }