Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Audio;
- using UnityEngine.UI;
- public class SettingManager : MonoBehaviour
- {
- public Toggle fullScreenToggle;
- public Dropdown resolutionDropdown;
- public Dropdown textureQualityDropdown;
- public Dropdown antialiasingDropdown;
- public Dropdown vSyncDropdown;
- public Slider masterVolumeSlider;
- public Slider musicVolumeSlider;
- public Slider sfxVolumeSlider;
- public Button applyButton;
- public Resolution[] resolutions;
- float master, music, sfx;
- public AudioMixer audioMixer;
- void OnEnable()
- {
- LoadSettings();
- fullScreenToggle.onValueChanged.AddListener(delegate { OnFullScreenToggle(); });
- resolutionDropdown.onValueChanged.AddListener(delegate { OnResolutionChange(); });
- textureQualityDropdown.onValueChanged.AddListener(delegate { OnTextureQualityChange(); });
- antialiasingDropdown.onValueChanged.AddListener(delegate { OnAntialiasingChange(); });
- vSyncDropdown.onValueChanged.AddListener(delegate { OnVSyncChange(); });
- applyButton.onClick.AddListener(delegate { OnApplyButtonClick(); });
- resolutions = Screen.resolutions;
- foreach (Resolution resolution in resolutions)
- {
- resolutionDropdown.options.Add(new Dropdown.OptionData(resolution.ToString()));
- }
- }
- public void OnFullScreenToggle()
- {
- Screen.fullScreen = fullScreenToggle.isOn;
- }
- public void OnResolutionChange()
- {
- Screen.SetResolution(resolutions[resolutionDropdown.value].width, resolutions[resolutionDropdown.value].height, Screen.fullScreen);
- }
- public void OnTextureQualityChange()
- {
- QualitySettings.masterTextureLimit = textureQualityDropdown.value;
- }
- public void OnAntialiasingChange()
- {
- QualitySettings.antiAliasing = (int)Mathf.Pow(2f, antialiasingDropdown.value);
- }
- public void OnVSyncChange()
- {
- QualitySettings.vSyncCount = vSyncDropdown.value;
- }
- public void SetMasterVolume(float masterVol)
- {
- audioMixer.SetFloat("masterVol", masterVol);
- }
- public void SetMusicVolume(float musicVol)
- {
- audioMixer.SetFloat("musicVol", musicVol);
- }
- public void SetSfxVolume(float sfxVol)
- {
- audioMixer.SetFloat("sfxVol", sfxVol);
- }
- public void OnApplyButtonClick()
- {
- SaveSettings();
- }
- public void SaveSettings()
- {
- PlayerPrefs.SetInt("fullscreen", Screen.fullScreen ? 1 : 0);
- PlayerPrefs.SetInt("resolutionDropdownValue", resolutionDropdown.value);
- PlayerPrefs.SetInt("width", resolutions[resolutionDropdown.value].width);
- PlayerPrefs.SetInt("height", resolutions[resolutionDropdown.value].height);
- PlayerPrefs.SetInt("textureQuality", QualitySettings.masterTextureLimit);
- PlayerPrefs.SetInt("antialiasingDropdownValue", antialiasingDropdown.value);
- PlayerPrefs.SetInt("antiAliasing", QualitySettings.antiAliasing);
- PlayerPrefs.SetInt("vSync", QualitySettings.vSyncCount);
- audioMixer.GetFloat("masterVol", out master);
- PlayerPrefs.SetFloat("masterVolume", master);
- audioMixer.GetFloat("musicVol", out music);
- PlayerPrefs.SetFloat("musicVolume", music);
- audioMixer.GetFloat("sfxVol", out sfx);
- PlayerPrefs.SetFloat("sfxVolume", sfx);
- PlayerPrefs.Save();
- }
- public void LoadSettings()
- {
- Screen.fullScreen = PlayerPrefs.GetInt("fullscreen") == 1 ? true : false;
- //Screen.SetResolution(PlayerPrefs.GetInt("width"), PlayerPrefs.GetInt("height"), Screen.fullScreen);
- QualitySettings.masterTextureLimit = PlayerPrefs.GetInt("textureQuality");
- QualitySettings.antiAliasing = PlayerPrefs.GetInt("antiAliasing");
- QualitySettings.vSyncCount = PlayerPrefs.GetInt("vSync");
- audioMixer.SetFloat("masterVol", PlayerPrefs.GetFloat("masterVolume"));
- audioMixer.SetFloat("musicVol", PlayerPrefs.GetFloat("musicVolume"));
- audioMixer.SetFloat("sfxVol", PlayerPrefs.GetFloat("sfxVolume"));
- fullScreenToggle.isOn = Screen.fullScreen;
- //resolutionDropdown.value = PlayerPrefs.GetInt("resolutionDropdownValue");
- textureQualityDropdown.value = QualitySettings.masterTextureLimit;
- antialiasingDropdown.value = PlayerPrefs.GetInt("antialiasingDropdownValue");
- vSyncDropdown.value = QualitySettings.vSyncCount;
- masterVolumeSlider.value = PlayerPrefs.GetFloat("masterVolume");
- musicVolumeSlider.value = PlayerPrefs.GetFloat("masterVolume");
- sfxVolumeSlider.value = PlayerPrefs.GetFloat("sfxVolume");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement