Files
BlueArchiveMiniGame/Assets/Scripts/HotUpdate/Main/UI/SettingWindow/AudioPanel.cs

37 lines
982 B
C#
Raw Normal View History

2025-09-17 18:56:28 +08:00
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Audio;
2025-09-29 07:45:07 +08:00
public class AudioPanel : UIBasePanel, ISettingsPanel
2025-09-17 18:56:28 +08:00
{
[SerializeField] private Slider masterVolumeSlider;
[SerializeField] private AudioMixer audioMixer;
private void OnEnable()
{
2025-09-29 07:45:07 +08:00
masterVolumeSlider.value = SettingsManager.Inst.CurrentSettings.masterVolume;
2025-09-17 18:56:28 +08:00
if (audioMixer == null) audioMixer = FindAnyObjectByType<AudioMixer>();
}
public void OnMasterVolumeChanged(float value)
{
2025-09-29 07:45:07 +08:00
SettingsManager.Inst.CurrentSettings.masterVolume = value;
2025-09-17 18:56:28 +08:00
SetVolume(value);
}
public void ApplySettings()
{
2025-09-29 07:45:07 +08:00
SetVolume(SettingsManager.Inst.CurrentSettings.masterVolume);
2025-09-17 18:56:28 +08:00
}
private void SetVolume(float volume)
{
if (audioMixer)
audioMixer.SetFloat("MasterVolume", Mathf.Log10(Mathf.Max(volume, 0.0001f)) * 20);
}
2025-09-29 07:45:07 +08:00
public void ResetToDefault()
{
throw new System.NotImplementedException();
}
2025-09-17 18:56:28 +08:00
}