94 lines
2.3 KiB
C#
94 lines
2.3 KiB
C#
using I2.Loc;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class SoundWidget : MonoBehaviour
|
|
{
|
|
public SoundSettings.SoundCategory soundCategory = SoundSettings.SoundCategory.MUSIC;
|
|
|
|
public Text text;
|
|
|
|
private Slider slider;
|
|
|
|
private SoundSettings soundSettings;
|
|
|
|
private void Start()
|
|
{
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
Refresh();
|
|
}
|
|
|
|
public void Refresh()
|
|
{
|
|
if ((bool)GlobalSettings.Instance)
|
|
{
|
|
soundSettings = GlobalSettings.Instance.soundSettings;
|
|
}
|
|
slider = GetComponent<Slider>();
|
|
if ((bool)soundSettings)
|
|
{
|
|
slider.value = soundSettings.GetVolume(soundCategory) * 100f;
|
|
}
|
|
else if (soundCategory == SoundSettings.SoundCategory.MUSIC)
|
|
{
|
|
slider.value = AudioController.GetCategoryVolume("Music") * 100f;
|
|
}
|
|
else if (soundCategory == SoundSettings.SoundCategory.SFX)
|
|
{
|
|
slider.value = AudioController.GetCategoryVolume("SFX") * 100f;
|
|
}
|
|
else if (soundCategory == SoundSettings.SoundCategory.AMBIENT)
|
|
{
|
|
slider.value = AudioController.GetCategoryVolume("Ambient") * 100f;
|
|
}
|
|
LanguageChanged();
|
|
}
|
|
|
|
public void UpdateValue()
|
|
{
|
|
if ((bool)soundSettings)
|
|
{
|
|
soundSettings.SetVolume(soundCategory, slider.value / 100f);
|
|
}
|
|
else if (soundCategory == SoundSettings.SoundCategory.MUSIC)
|
|
{
|
|
AudioController.SetCategoryVolume("Music", slider.value / 100f);
|
|
}
|
|
else if (soundCategory == SoundSettings.SoundCategory.SFX)
|
|
{
|
|
AudioController.SetCategoryVolume("SFX", slider.value / 100f);
|
|
}
|
|
else if (soundCategory == SoundSettings.SoundCategory.AMBIENT)
|
|
{
|
|
AudioController.SetCategoryVolume("Ambient", slider.value / 100f);
|
|
}
|
|
LanguageChanged();
|
|
text.color = new Color(text.color.r, text.color.g, text.color.b, (!slider.interactable) ? slider.colors.disabledColor.a : 1f);
|
|
}
|
|
|
|
public void LanguageChanged()
|
|
{
|
|
string term = string.Empty;
|
|
if (soundCategory == SoundSettings.SoundCategory.GLOBAL)
|
|
{
|
|
term = string.Empty;
|
|
}
|
|
else if (soundCategory == SoundSettings.SoundCategory.MUSIC)
|
|
{
|
|
term = "GUI/OPTIONS_MUSIC";
|
|
}
|
|
else if (soundCategory == SoundSettings.SoundCategory.SFX)
|
|
{
|
|
term = "GUI/OPTIONS_SOUNDS";
|
|
}
|
|
else if (soundCategory == SoundSettings.SoundCategory.AMBIENT)
|
|
{
|
|
term = "GUI/OPTIONS_AMBIENT";
|
|
}
|
|
text.text = LocalizationManager.GetTermTranslation(term) + ": " + slider.value + "%";
|
|
}
|
|
}
|