You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
2.3 KiB
103 lines
2.3 KiB
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class SettingsManager : MonoBehaviour {
|
|
|
|
public static SettingsManager Instance {
|
|
get;
|
|
set;
|
|
}
|
|
|
|
/// <summary>
|
|
/// The given music volume slider element
|
|
/// </summary>
|
|
public Slider musicSlider;
|
|
|
|
/// <summary>
|
|
/// The given sfx volume slider element
|
|
/// </summary>
|
|
public Slider sfxSlider;
|
|
|
|
private Settings settings;
|
|
|
|
void Awake() {
|
|
Instance = this;
|
|
}
|
|
|
|
void Start() {
|
|
ApplySettings(GameManager.Instance.settings);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the musics volume for whole environment and applies volume to global settings
|
|
/// </summary>
|
|
/// <param name="volume"></param>
|
|
public void SetMusicsVolume(float volume) {
|
|
SetMusicsVolumeSoundSystem(volume);
|
|
|
|
//Changes settings
|
|
settings.audio.MusicsVolume = volume;
|
|
GameManager.Instance.ApplySettings(settings);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the sfx volume for whole environment and applies volume to global settings
|
|
/// </summary>
|
|
/// <param name="volume"></param>
|
|
public void SetSFXVolume(float volume) {
|
|
SetSFXVolumeSoundSystem(volume);
|
|
|
|
//Changes settings
|
|
settings.audio.SfxVolume = volume;
|
|
GameManager.Instance.ApplySettings(settings);
|
|
}
|
|
|
|
private void SetMusicsVolumeSoundSystem(float volume) {
|
|
AudioManager.Instance.SetMusicsVolume(volume);
|
|
|
|
Debug.Log("Music volume changed: " + volume.ToString("0.00"));
|
|
}
|
|
|
|
private void SetSFXVolumeSoundSystem(float volume) {
|
|
AudioManager.Instance.SetSFXVolume(volume);
|
|
|
|
Debug.Log("SFX volume changed: " + volume.ToString("0.00"));
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Applies given settings to global settings and executes them
|
|
/// </summary>
|
|
/// <param name="settings"></param>
|
|
public void ApplySettings(Settings settings) {
|
|
this.settings = settings;
|
|
|
|
ApplyAudioSettings(settings.audio);
|
|
|
|
Debug.Log("All settings successfully applied");
|
|
}
|
|
|
|
private void ApplyAudioSettings(Settings.Audio settings) {
|
|
float music = settings.MusicsVolume;
|
|
float sfx = settings.SfxVolume;
|
|
|
|
if (musicSlider.value == music) {
|
|
musicSlider.value = music;
|
|
SetMusicsVolumeSoundSystem(music);
|
|
}
|
|
else {
|
|
musicSlider.value = music;
|
|
}
|
|
|
|
if (sfxSlider.value == sfx) {
|
|
sfxSlider.value = sfx;
|
|
SetSFXVolumeSoundSystem(sfx);
|
|
}
|
|
else {
|
|
sfxSlider.value = sfx;
|
|
}
|
|
|
|
Debug.Log("Applied sound settings: Music=" + settings.MusicsVolume.ToString("0.00")
|
|
+ " SFX=" + settings.SfxVolume.ToString("0.00"));
|
|
}
|
|
}
|
|
|