using TMPro; using UnityEngine; using System.Collections.Generic; using UnityEngine.Rendering.PostProcessing; using UnityEngine.UI; public class SettingsPanel : MonoBehaviour { public GameObject settingsPanel; public GameObject settingsPanelDeactivator; public bool DisableSettingsPanelWhenLinkedGameobjectIsActivated = false; public TMP_Dropdown GraphicsQualityDropdown; public Toggle FullscreenToggle; public PostProcessVolume PostProcessVolume; public List PostProcessingVolumes = new() { }; private void Update() { if (settingsPanel && DisableSettingsPanelWhenLinkedGameobjectIsActivated && settingsPanelDeactivator.activeInHierarchy) { settingsPanel.SetActive(false); settingsPanelDeactivator.SetActive(false); } } public void AcTogglePostProcessing(bool IsEnabled) { if (IsEnabled) PlayerPrefs.SetInt("PostProcessingEnabled", 1); else PlayerPrefs.SetInt("PostProcessingEnabled", 0); foreach (PostProcessVolume volume in PostProcessingVolumes) volume.enabled = IsEnabled; } private void Start() { if (GraphicsQualityDropdown) { string[] QualityNames = QualitySettings.names; List Options = new(); GraphicsQualityDropdown.ClearOptions(); foreach (string QualityName in QualityNames) { Options.Add(new TMP_Dropdown.OptionData(QualityName)); } GraphicsQualityDropdown.AddOptions(Options); if (!PlayerPrefs.HasKey("QualityLevel")) GraphicsQualityDropdown.value = QualitySettings.GetQualityLevel(); else { QualitySettings.SetQualityLevel(PlayerPrefs.GetInt("QualityLevel")); GraphicsQualityDropdown.value = PlayerPrefs.GetInt("QualityLevel"); } if (PlayerPrefs.HasKey("FullscreenState") && FullscreenToggle) { FullscreenToggle.isOn = bool.Parse(PlayerPrefs.GetString("FullscreenState")); } } } public void SwitchQualitySettings(int index) { if (GraphicsQualityDropdown) { PlayerPrefs.SetInt("QualityLevel", index); QualitySettings.SetQualityLevel(index); } } }