1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Sirenix.OdinInspector;
- using UnityEngine.Audio;
- namespace KairoEngine.Core.ConfigOptions
- {
- [CreateAssetMenu(fileName = "FullscreenConfigOption", menuName = "KairoEngine/ConfigOptions/Fullscreen", order = 3), HideMonoScript]
- public class FullscreenConfigOption : ConfigOptionBase
- {
- [PropertyOrder(5)] public bool defaultIsFullscreen = true;
- [PropertyOrder(6), TextArea(), HideLabel, PropertySpace(4,0)] public string description;
- private bool isFullscreen = true;
- private bool showDebug = false;
- public override ConfigOptionUiData GetUiData()
- {
- var checkboxData = new ConfigOptionUiData.CheckboxData(defaultIsFullscreen);
- return new ConfigOptionUiData(title, description, checkboxData);
- }
- public override void LoadValue(bool debug)
- {
- isFullscreen = PlayerPrefs.GetInt(id, defaultIsFullscreen ? 1 : 0) == 1 ? true : false;
- showDebug = debug;
- ApplyConfig();
- }
- public override void SetDefaultValue()
- {
- isFullscreen = defaultIsFullscreen;
- PlayerPrefs.SetInt(id, isFullscreen ? 1 : 0);
- ApplyConfig();
- }
- public override void SetValue(ConfigOptionData data, bool save = false)
- {
- isFullscreen = data.intValue == 1 ? true : false;
- ApplyConfig();
- if(save) PlayerPrefs.SetInt(id, data.intValue);
- }
- private void ApplyConfig()
- {
- if(Screen.fullScreen != isFullscreen)
- {
- Screen.fullScreen = isFullscreen;
- if(showDebug) Debug.Log($"Changed display mode to {(Screen.fullScreen ? "fullscreen" : "windowed")}");
- }
- else if(showDebug) Debug.Log($"Display mode is already set to {(Screen.fullScreen ? "fullscreen" : "windowed")}");
- }
- [Button("Apply Default"), PropertyOrder(100), PropertySpace(4,4)]
- private void ApplyDefaultConfig()
- {
- isFullscreen = defaultIsFullscreen;
- ApplyConfig();
- }
- }
- }
|