| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.Rendering.PostProcessing;
- using UnityEditor;
- public class settings : MonoBehaviour
- {
- public AudioSource audSrc;
- public GameObject[] settingsSections;
- public Button[] settingsSectionsBtns;
- public AudioClip settingsSectionSelectedSFX;
- public AudioClip settingsChangedSFX;
- public AudioClip onHoverSfx;
- [Header("Graphics")]
- public Toggle vsync;
- public Dropdown shadows;
- public Dropdown aa;
- public Dropdown pp;
- public Dropdown particles;
- public Dropdown textureQ;
- public Dropdown lightningQ;
- public void show()
- {
- gameObject.SetActive(true);
- }
- public void hide()
- {
- gameObject.SetActive(false);
- }
- void Start()
- {
- DontDestroyOnLoad(gameObject);
- SettingPage.instance = this;
- vsync.onValueChanged.AddListener((bool b) => {
- PlayerPrefs.SetInt("vsync", (b) ? 1 : 0);
- PlayerPrefs.Save();
- playSettingsChangedSFX();
- reloadGraphicSettings();
- });
- shadows.onValueChanged.AddListener((int option) =>
- {
- PlayerPrefs.SetInt("shadows", option);
- PlayerPrefs.Save();
- playSettingsChangedSFX();
- reloadGraphicSettings();
- });
- aa.onValueChanged.AddListener((int option) =>
- {
- PlayerPrefs.SetInt("aa", option);
- PlayerPrefs.Save();
- playSettingsChangedSFX();
- reloadGraphicSettings();
- });
- pp.onValueChanged.AddListener((int option) =>
- {
- PlayerPrefs.SetInt("pp", option);
- PlayerPrefs.Save();
- playSettingsChangedSFX();
- reloadGraphicSettings();
- });
- particles.onValueChanged.AddListener((int option) =>
- {
- PlayerPrefs.SetInt("particles", option);
- PlayerPrefs.Save();
- playSettingsChangedSFX();
- reloadGraphicSettings();
- });
- textureQ.onValueChanged.AddListener((int option) =>
- {
- PlayerPrefs.SetInt("textureQ", option);
- PlayerPrefs.Save();
- playSettingsChangedSFX();
- reloadGraphicSettings();
- });
- lightningQ.onValueChanged.AddListener((int option) =>
- {
- PlayerPrefs.SetInt("lightningQ", option);
- PlayerPrefs.Save();
- playSettingsChangedSFX();
- reloadGraphicSettings();
- });
- reloadGraphicSettings();
- if (settingsSections.Length != settingsSectionsBtns.Length) { Debug.LogError("IMBALANCED SETTINGS CONFIG!"); }
- else
- {
- for (int i = 0; i < settingsSectionsBtns.Length; i++)
- {
- int x = i;
- settingsSectionsBtns[x].onClick.AddListener(() => { onSettingsSectionClick(x); });
- }
- }
- onSettingsSectionClick(0);
- }
- void onSettingsSectionClick(int i)
- {
- Debug.Log("Selected " + i + " button");
- for (int x = 0; x < settingsSectionsBtns.Length; x++)
- {
- settingsSectionsBtns[x].interactable = (x != i);
- settingsSections[x].SetActive((x == i));
- }
- reloadGraphicSettings();
- audSrc.PlayOneShot(settingsSectionSelectedSFX);
- }
- void playSettingsChangedSFX()
- {
- audSrc.PlayOneShot(settingsChangedSFX);
- }
- public void OnHoverSFX()
- {
- audSrc.PlayOneShot(onHoverSfx);
- }
- // Update is called once per frame
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.Escape))
- {
- hide();
- }
- }
- public void reloadGraphicSettings()
- {
- //Read all settings from prefs
- vsync.isOn = PlayerPrefs.GetInt("vsync") == 1;
- shadows.value = PlayerPrefs.GetInt("shadows");
- aa.value = PlayerPrefs.GetInt("aa");
- pp.value = PlayerPrefs.GetInt("pp");
- particles.value = PlayerPrefs.GetInt("particles");
- textureQ.value = PlayerPrefs.GetInt("textureQ");
- lightningQ.value = PlayerPrefs.GetInt("lightningQ");
- //APPLY EACH
- QualitySettings.vSyncCount = PlayerPrefs.GetInt("vsync");
- QualitySettings.softParticles = pp.value == 1;
- switch (shadows.value)
- {
- case 0:
- QualitySettings.shadows = ShadowQuality.All;
- QualitySettings.shadowResolution = ShadowResolution.VeryHigh;
- break;
- case 1:
- QualitySettings.shadows = ShadowQuality.All;
- QualitySettings.shadowResolution = ShadowResolution.High;
- break;
- case 2:
- QualitySettings.shadows = ShadowQuality.HardOnly;
- QualitySettings.shadowResolution = ShadowResolution.Medium;
- break;
- case 3:
- QualitySettings.shadows = ShadowQuality.HardOnly;
- QualitySettings.shadowResolution = ShadowResolution.Low;
- break;
- case 4:
- QualitySettings.shadows = ShadowQuality.Disable;
- break;
- }
- switch (aa.value)
- {
- case 0:
- QualitySettings.antiAliasing = 0;
- break;
- case 1:
- QualitySettings.antiAliasing = 2;
- break;
- case 2:
- QualitySettings.antiAliasing = 4;
- break;
- case 3:
- QualitySettings.antiAliasing = 8;
- break;
- }
- PostProcessVolume[] volumes = FindObjectsOfType<PostProcessVolume>();
- switch (pp.value)
- {
- case 0:
- foreach (PostProcessVolume vol in volumes)
- {
- vol.enabled = true;
- }
- break;
- case 3:
- foreach(PostProcessVolume vol in volumes)
- {
- vol.enabled = false;
- }
- break;
- }
- QualitySettings.masterTextureLimit = textureQ.value;
- switch (lightningQ.value)
- {
- case 0:
- // PlayerSettings.colorSpace = ColorSpace.Linear;
- break;
- case 1:
- // PlayerSettings.colorSpace = ColorSpace.Gamma;
- break;
- }
- }
- }
- public static class SettingPage
- {
- public static settings instance;
- }
|