This commit is contained in:
Gerard Gascón 2025-04-24 17:19:36 +02:00
commit 001bb14f16
951 changed files with 270074 additions and 0 deletions

View file

@ -0,0 +1,96 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using UnityEngine.UI;
using TMPro;
using UnityEngine.Audio;
public class MenuController : MonoBehaviour{
[SerializeField] AudioMixer mainMixer = default;
[Tooltip("The music volume the first time you start the game")] [SerializeField, Range(0, 1)] float defaultMusicValue = 1f;
[Tooltip("The SFX volume the first time you start the game")] [SerializeField, Range(0, 1)] float defaultSfxValue = 1f;
[SerializeField] Slider musicSlider = default;
[SerializeField] Slider sfxSlider = default;
[Space]
[SerializeField] TMP_Dropdown qualityDropdown = default;
int qualitySelected;
[Space]
[SerializeField] TMP_Dropdown resolutionDropdown = default;
Resolution[] resolutions;
int currentResolutionIndex;
void Awake(){
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();
}
if(qualityDropdown != null){
if (PlayerPrefs.HasKey("QualitySelected")){
qualitySelected = PlayerPrefs.GetInt("QualitySelected");
}else{
qualitySelected = qualityDropdown.value;
}
qualityDropdown.value = qualitySelected;
QualitySettings.SetQualityLevel(qualitySelected);
}
}
void Start(){
if (musicSlider != null && sfxSlider != null){
musicSlider.value = PlayerPrefs.GetFloat("MusicVolume", defaultMusicValue);
sfxSlider.value = PlayerPrefs.GetFloat("SFXVolume", defaultSfxValue);
}
}
//Needs a slider between 0.0001 and 1
public void SetMusicVolume(float sliderValue){
mainMixer.SetFloat("Master", Mathf.Log10(sliderValue) * 20);
PlayerPrefs.SetFloat("MusicVolume", sliderValue);
}
//Needs a slider between 0.0001 and 1
public void SetSfxVolume(float sliderValue){
mainMixer.SetFloat("SFX", Mathf.Log10(sliderValue) * 20);
PlayerPrefs.SetFloat("SFXVolume", sliderValue);
}
public void SetQuality(int qualityIndex){
QualitySettings.SetQualityLevel(qualityIndex);
PlayerPrefs.SetInt("QualitySelected", qualityIndex);
}
public void SetResolution(int resolutionIndex){
Resolution resolution = resolutions[resolutionIndex];
Screen.SetResolution(resolution.width, resolution.height, Screen.fullScreen);
}
public void Play(){
}
public void Quit(){
Application.Quit();
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1e26602e8c04bfd488f5d150c29aed57
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: