69 lines
2.0 KiB
C#
69 lines
2.0 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Ashwild.Settings
|
|
{
|
|
public class AudioSettingsSubPanel : SettingsSubPanel
|
|
{
|
|
[Header("Master")]
|
|
[SerializeField] private Slider masterSlider;
|
|
[SerializeField] private TMP_Text masterLabel;
|
|
|
|
[Header("Music")]
|
|
[SerializeField] private Slider musicSlider;
|
|
[SerializeField] private TMP_Text musicLabel;
|
|
|
|
[Header("SFX")]
|
|
[SerializeField] private Slider sfxSlider;
|
|
[SerializeField] private TMP_Text sfxLabel;
|
|
|
|
private bool wiring;
|
|
|
|
private void Awake()
|
|
{
|
|
masterSlider.onValueChanged.AddListener(OnMasterChanged);
|
|
musicSlider.onValueChanged.AddListener(OnMusicChanged);
|
|
sfxSlider.onValueChanged.AddListener(OnSfxChanged);
|
|
}
|
|
|
|
public override void Refresh()
|
|
{
|
|
SettingsManager s = SettingsManager.Instance;
|
|
if (s == null) return;
|
|
|
|
wiring = true;
|
|
masterSlider.SetValueWithoutNotify(s.MasterVolume);
|
|
musicSlider.SetValueWithoutNotify(s.MusicVolume);
|
|
sfxSlider.SetValueWithoutNotify(s.SfxVolume);
|
|
UpdateLabel(masterLabel, s.MasterVolume);
|
|
UpdateLabel(musicLabel, s.MusicVolume);
|
|
UpdateLabel(sfxLabel, s.SfxVolume);
|
|
wiring = false;
|
|
}
|
|
|
|
private void OnMasterChanged(float v)
|
|
{
|
|
UpdateLabel(masterLabel, v);
|
|
if (!wiring) SettingsManager.Instance.SetMasterVolume(v);
|
|
}
|
|
|
|
private void OnMusicChanged(float v)
|
|
{
|
|
UpdateLabel(musicLabel, v);
|
|
if (!wiring) SettingsManager.Instance.SetMusicVolume(v);
|
|
}
|
|
|
|
private void OnSfxChanged(float v)
|
|
{
|
|
UpdateLabel(sfxLabel, v);
|
|
if (!wiring) SettingsManager.Instance.SetSfxVolume(v);
|
|
}
|
|
|
|
private static void UpdateLabel(TMP_Text label, float value01)
|
|
{
|
|
if (label != null) label.text = $"{Mathf.RoundToInt(value01 * 100f)}%";
|
|
}
|
|
}
|
|
}
|