FullscreenConfigOption.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Sirenix.OdinInspector;
  5. using UnityEngine.Audio;
  6. namespace KairoEngine.Core.ConfigOptions
  7. {
  8. [CreateAssetMenu(fileName = "FullscreenConfigOption", menuName = "KairoEngine/ConfigOptions/Fullscreen", order = 3), HideMonoScript]
  9. public class FullscreenConfigOption : ConfigOptionBase
  10. {
  11. [PropertyOrder(5)] public bool defaultIsFullscreen = true;
  12. [PropertyOrder(6), TextArea(), HideLabel, PropertySpace(4,0)] public string description;
  13. private bool isFullscreen = true;
  14. private bool showDebug = false;
  15. public override ConfigOptionUiData GetUiData()
  16. {
  17. var checkboxData = new ConfigOptionUiData.CheckboxData(defaultIsFullscreen);
  18. return new ConfigOptionUiData(title, description, checkboxData);
  19. }
  20. public override void LoadValue(bool debug)
  21. {
  22. isFullscreen = PlayerPrefs.GetInt(id, defaultIsFullscreen ? 1 : 0) == 1 ? true : false;
  23. showDebug = debug;
  24. ApplyConfig();
  25. }
  26. public override void SetDefaultValue()
  27. {
  28. isFullscreen = defaultIsFullscreen;
  29. PlayerPrefs.SetInt(id, isFullscreen ? 1 : 0);
  30. ApplyConfig();
  31. }
  32. public override void SetValue(ConfigOptionData data, bool save = false)
  33. {
  34. isFullscreen = data.intValue == 1 ? true : false;
  35. ApplyConfig();
  36. if(save) PlayerPrefs.SetInt(id, data.intValue);
  37. }
  38. private void ApplyConfig()
  39. {
  40. if(Screen.fullScreen != isFullscreen)
  41. {
  42. Screen.fullScreen = isFullscreen;
  43. if(showDebug) Debug.Log($"Changed display mode to {(Screen.fullScreen ? "fullscreen" : "windowed")}");
  44. }
  45. else if(showDebug) Debug.Log($"Display mode is already set to {(Screen.fullScreen ? "fullscreen" : "windowed")}");
  46. }
  47. [Button("Apply Default"), PropertyOrder(100), PropertySpace(4,4)]
  48. private void ApplyDefaultConfig()
  49. {
  50. isFullscreen = defaultIsFullscreen;
  51. ApplyConfig();
  52. }
  53. }
  54. }