You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.5 KiB
C#
49 lines
1.5 KiB
C#
3 weeks ago
|
using System;
|
||
|
using Unity.BossRoom.Audio;
|
||
|
using Unity.BossRoom.Utils;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.UI;
|
||
|
|
||
|
namespace Unity.BossRoom.Gameplay.UI
|
||
|
{
|
||
|
|
||
|
public class UISettingsPanel : MonoBehaviour
|
||
|
{
|
||
|
[SerializeField]
|
||
|
private Slider m_MasterVolumeSlider;
|
||
|
|
||
|
[SerializeField]
|
||
|
private Slider m_MusicVolumeSlider;
|
||
|
|
||
|
private void OnEnable()
|
||
|
{
|
||
|
// Note that we initialize the slider BEFORE we listen for changes (so we don't get notified of our own change!)
|
||
|
m_MasterVolumeSlider.value = ClientPrefs.GetMasterVolume();
|
||
|
m_MasterVolumeSlider.onValueChanged.AddListener(OnMasterVolumeSliderChanged);
|
||
|
|
||
|
// initialize music slider similarly.
|
||
|
m_MusicVolumeSlider.value = ClientPrefs.GetMusicVolume();
|
||
|
m_MusicVolumeSlider.onValueChanged.AddListener(OnMusicVolumeSliderChanged);
|
||
|
}
|
||
|
|
||
|
private void OnDisable()
|
||
|
{
|
||
|
m_MasterVolumeSlider.onValueChanged.RemoveListener(OnMasterVolumeSliderChanged);
|
||
|
m_MusicVolumeSlider.onValueChanged.RemoveListener(OnMusicVolumeSliderChanged);
|
||
|
}
|
||
|
|
||
|
private void OnMasterVolumeSliderChanged(float newValue)
|
||
|
{
|
||
|
ClientPrefs.SetMasterVolume(newValue);
|
||
|
AudioMixerConfigurator.Instance.Configure();
|
||
|
}
|
||
|
|
||
|
private void OnMusicVolumeSliderChanged(float newValue)
|
||
|
{
|
||
|
ClientPrefs.SetMusicVolume(newValue);
|
||
|
AudioMixerConfigurator.Instance.Configure();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|