61 lines
2.3 KiB
C#
61 lines
2.3 KiB
C#
using System;
|
|
using TemplateUnity.Core;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace TemplateUnity.MainMenu
|
|
{
|
|
public class UIOptionSection: UICore
|
|
{
|
|
public static UIOptionSection Instance { get; private set; }
|
|
|
|
public static event EventHandler<float> onAnyMasterVolumeValueChanged;
|
|
public static event EventHandler<float> onAnyMusicVolumeValueChanged;
|
|
public static event EventHandler<float> onAnySfxVolumeValueChanged;
|
|
|
|
public event EventHandler onExitTrigger;
|
|
|
|
[SerializeField] private Button exitButton;
|
|
[SerializeField] private Slider masterVolume;
|
|
[SerializeField] private Slider musicVolume;
|
|
[SerializeField] private Slider sfxVolume;
|
|
|
|
private void Awake()
|
|
{
|
|
if (Instance)
|
|
{
|
|
Debug.LogWarning($"{typeof(UIOptionSection)} already instantiated! {transform}");
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
|
|
Instance = this;
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
exitButton.Select();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
exitButton.onClick.AddListener(() => onExitTrigger?.Invoke(this, EventArgs.Empty));
|
|
|
|
masterVolume.onValueChanged.AddListener(amount => onAnyMasterVolumeValueChanged?.Invoke(this, amount));
|
|
musicVolume.onValueChanged.AddListener(amount => onAnyMusicVolumeValueChanged?.Invoke(this, amount));
|
|
sfxVolume.onValueChanged.AddListener(amount => onAnySfxVolumeValueChanged?.Invoke(this, amount));
|
|
|
|
masterVolume.maxValue = OptionHandler.Instance.MaxVolume;
|
|
musicVolume.maxValue = OptionHandler.Instance.MaxVolume;
|
|
sfxVolume.maxValue = OptionHandler.Instance.MaxVolume;
|
|
|
|
masterVolume.value = OptionHandler.Instance.MasterVolume;
|
|
musicVolume.value = OptionHandler.Instance.MusicVolume;
|
|
sfxVolume.value = OptionHandler.Instance.SfxVolume;
|
|
|
|
MainMenuManager.Instance.onMainSectionReveal += (_, _) => Hide();
|
|
MainMenuManager.Instance.onSaveSectionReveal += (_, _) => Hide();
|
|
MainMenuManager.Instance.onOptionsSectionReveal += (_, _) => Show();
|
|
}
|
|
}
|
|
} |