80 lines
2.4 KiB
C#
80 lines
2.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using System.Linq;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
|
|
public class SettingsMenu : MonoBehaviour{
|
|
|
|
[SerializeField] GameObject startButton;
|
|
[SerializeField] GameObject[] mainMenu;
|
|
|
|
[Space]
|
|
[SerializeField] TMP_Dropdown resolutionDropdown = default;
|
|
Resolution[] resolutions;
|
|
int currentResolutionIndex;
|
|
|
|
void Awake(){
|
|
foreach(GameObject o in mainMenu){
|
|
o.SetActive(false);
|
|
}
|
|
|
|
if(resolutionDropdown != null){
|
|
resolutions = Screen.resolutions.Select(resolution => new Resolution { width = resolution.width, height = resolution.height }).Distinct().ToArray();
|
|
resolutionDropdown.ClearOptions();
|
|
|
|
List<string> options = new List<string>();
|
|
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.currentResolution.width && resolutions[i].height == Screen.currentResolution.height){
|
|
currentResolutionIndex = i;
|
|
}
|
|
}
|
|
|
|
resolutions.Reverse();
|
|
|
|
resolutionDropdown.AddOptions(options);
|
|
resolutionDropdown.value = currentResolutionIndex;
|
|
resolutionDropdown.RefreshShownValue();
|
|
}
|
|
}
|
|
|
|
bool started;
|
|
void Update(){
|
|
if (Input.anyKeyDown && !started){
|
|
AudioManager.instance.PlayOneShot("Start");
|
|
AudioManager.instance.Play("Menu");
|
|
startButton.SetActive(false);
|
|
foreach(GameObject o in mainMenu){
|
|
o.SetActive(true);
|
|
}
|
|
started = true;
|
|
}
|
|
}
|
|
|
|
public void SetQuality(int qualityIndex){
|
|
QualitySettings.SetQualityLevel(qualityIndex);
|
|
}
|
|
|
|
public void SetResolution(int resolutionIndex){
|
|
Resolution resolution = resolutions[resolutionIndex];
|
|
|
|
Screen.SetResolution(resolution.width, resolution.height, Screen.fullScreen);
|
|
}
|
|
|
|
public void Play(){
|
|
if (PlayerPrefs.HasKey("Tutorial")){
|
|
LevelLoader.instance.LoadScene(2);
|
|
}else{
|
|
LevelLoader.instance.LoadScene(1);
|
|
}
|
|
AudioManager.instance.PlayOneShot("Play");
|
|
}
|
|
|
|
public void Quit(){
|
|
Application.Quit();
|
|
}
|
|
}
|