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.UI;
- using UnityEngine.SceneManagement;
- using TMPro;
- public class MenuController : MonoBehaviour
- {
- [Header("Volume Setting")]
- [SerializeField] private Slider volumeSlider = null;
- [SerializeField] private float defaultVolume = 1.0f;
- [Header("Gameplay Settings")]
- [SerializeField] private Slider controllerSenSlider = null;
- [SerializeField] private int defaultSen = 4;
- public int mainControllerSen = 4;
- [Header("Toggle Settings")]
- [SerializeField] private Toggle invertYToggle = null;
- [Header("Graphics Settings")]
- [SerializeField] private Slider brightnessSlider = null;
- [SerializeField] private float defaultBrightness = 1;
- private int _qualityLevel;
- private bool _isFullScreen;
- private float _brightnessLevel;
- [Space(10)]
- public TMP_Dropdown qualityDropdown;
- [SerializeField] private Toggle fullscreenToggle;
- [Header("Confirmation")]
- [SerializeField] private GameObject confirmationPrompt = null;
- [Header("Levels to Load")]
- public string _newGameLevel;
- private string levelToLoad;
- [SerializeField] private GameObject noSavedGameDialog = null;
- [Header("Resolution Dropdowns")]
- public TMP_Dropdown resolutionDropdown;
- private Resolution[] resolutions;
- private void Start()
- {
- resolutions = Screen.resolutions;
- resolutionDropdown.ClearOptions();
- List<string> options = new List<string>();
- int currentResolutionIndex = 0;
- for (int i = 0; i < resolutions.Length; i++)
- {
- string option = resolutions[i].width + " x " + resolutions[i].height;
- options.Add(option);
- if(resolutions[i].width == Screen.width && resolutions[i].height == Screen.height)
- {
- currentResolutionIndex = i;
- }
- }
- resolutionDropdown.AddOptions(options);
- resolutionDropdown.value = currentResolutionIndex;
- resolutionDropdown.RefreshShownValue();
- }
- public void SetResolution(int resolutionIndex)
- {
- Resolution resolution = resolutions[resolutionIndex];
- Screen.SetResolution(resolution.width, resolution.height, Screen.fullScreen);
- }
- public void NewGameDialogYes()
- {
- SceneManager.LoadScene(_newGameLevel);
- }
- public void LoadGameDialogYes()
- {
- if (PlayerPrefs.HasKey("SavedLevel"))
- {
- levelToLoad = PlayerPrefs.GetString("SavedLevel");
- SceneManager.LoadScene(levelToLoad);
- }
- else
- {
- noSavedGameDialog.SetActive(true);
- }
- }
- public void ExitButton()
- {
- Application.Quit();
- }
- public void SetVolume(float volume)
- {
- AudioListener.volume = volume;
- }
- public void VolumeApply()
- {
- PlayerPrefs.SetFloat("masterVolume", AudioListener.volume);
- StartCoroutine(ConfirmationBox());
- }
- public void SetControllerSen(float sensitivity)
- {
- mainControllerSen = Mathf.RoundToInt(sensitivity);
- }
- public void GameplayApply()
- {
- if (invertYToggle.isOn)
- {
- PlayerPrefs.SetInt("masterInvertY", 1);
- }
- else
- {
- PlayerPrefs.SetInt("masterInvertY", 0);
- }
- PlayerPrefs.SetFloat("masterSen", mainControllerSen);
- StartCoroutine(ConfirmationBox());
- }
- public void SetBrightness(float brightness)
- {
- _brightnessLevel = brightness;
- }
- public void setFullScreen(bool isFullscreen)
- {
- _isFullScreen = isFullscreen;
- }
- public void SetQuality(int qualityIndex)
- {
- _qualityLevel = qualityIndex;
- }
- public void GraphicsApply()
- {
- PlayerPrefs.SetFloat("masterBrightness", _brightnessLevel);
- PlayerPrefs.SetInt("masterQuality", _qualityLevel);
- QualitySettings.SetQualityLevel(_qualityLevel);
- PlayerPrefs.SetInt("masterFullscreen", (_isFullScreen ? 1 : 0));
- Screen.fullScreen = _isFullScreen;
- StartCoroutine(ConfirmationBox());
- }
- public void ResetButton()
- {
- brightnessSlider.value = defaultBrightness;
- Debug.Log("Current Brightness: " + defaultBrightness.ToString());
- qualityDropdown.value = 2;
- QualitySettings.SetQualityLevel(1);
- Debug.Log("Current Quality: " + qualityDropdown.value.ToString());
- fullscreenToggle.isOn = false;
- Screen.fullScreen = false;
- Debug.Log("Fullscreen or Windowed?: " + fullscreenToggle.ToString());
- Resolution currentResolution = Screen.currentResolution;
- Screen.SetResolution(currentResolution.width, currentResolution.height, Screen.fullScreen);
- resolutionDropdown.value = resolutions.Length;
- GraphicsApply();
- Debug.Log("Current Resolution: " + currentResolution.ToString());
- AudioListener.volume = defaultVolume;
- volumeSlider.value = defaultVolume;
- VolumeApply();
- Debug.Log("Current Volume: " + volumeSlider.value.ToString());
- controllerSenSlider.value = defaultSen;
- mainControllerSen = defaultSen;
- invertYToggle.isOn = false;
- GameplayApply();
- Debug.Log("Current Sensitivity: " + defaultSen.ToString());
- Debug.Log("Inverted Y-Axis?: " + invertYToggle.ToString());
- }
- public IEnumerator ConfirmationBox()
- {
- confirmationPrompt.SetActive(true);
- yield return new WaitForSeconds(2);
- confirmationPrompt.SetActive(false);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement