141 lines
3.6 KiB
C#
141 lines
3.6 KiB
C#
using System;
|
|
using System.Collections;
|
|
using BlueWater;
|
|
using BlueWater.Audios;
|
|
using BlueWater.Uis;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.InputSystem;
|
|
using UnityEngine.UI;
|
|
|
|
public class TitleOptions : PopupUi
|
|
{
|
|
[SerializeField]
|
|
private GameObject _panel;
|
|
|
|
[SerializeField]
|
|
private Slider _masterVolume;
|
|
|
|
[SerializeField]
|
|
private Slider _bgmVolume;
|
|
|
|
[SerializeField]
|
|
private Slider _sfxVolume;
|
|
|
|
[SerializeField]
|
|
private TMP_Dropdown _languageDropdown;
|
|
|
|
private AudioManager _audioManager;
|
|
|
|
private InputAction _interactionEAction;
|
|
private InputAction _closeOptionsAction;
|
|
public Action CloseOptions;
|
|
|
|
private void Start()
|
|
{
|
|
_interactionEAction = PlayerInputKeyManager.Instance.GetAction(InputActionMaps.TycoonUi, TycoonUiActions.InteractionE);
|
|
_closeOptionsAction = PlayerInputKeyManager.Instance.GetAction(InputActionMaps.TycoonUi, TycoonUiActions.Cancel);
|
|
|
|
_audioManager = AudioManager.Instance;
|
|
|
|
var masterVolume = ES3.Load("MasterVolume", 1f);
|
|
SetMasterVolume(masterVolume);
|
|
|
|
var bgmVolume = ES3.Load("BgmVolume", 1f);
|
|
SetBgmVolume(bgmVolume);
|
|
|
|
var sfxVolume = ES3.Load("SfxVolume", 1f);
|
|
SetSfxVolume(sfxVolume);
|
|
|
|
StartCoroutine(nameof(InitializeLanguage));
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (_interactionEAction != null)
|
|
{
|
|
_interactionEAction.performed -= OnInteractionE;
|
|
}
|
|
|
|
if (_closeOptionsAction != null)
|
|
{
|
|
_closeOptionsAction.performed -= OnCloseOptions;
|
|
}
|
|
}
|
|
|
|
public override void Open()
|
|
{
|
|
PopupUiController.RegisterPopup(this);
|
|
_panel.SetActive(true);
|
|
IsOpened = true;
|
|
}
|
|
|
|
public override void Close()
|
|
{
|
|
_panel.SetActive(false);
|
|
PopupUiController.UnregisterPopup(this);
|
|
IsOpened = false;
|
|
}
|
|
|
|
public override void EnableInput()
|
|
{
|
|
_interactionEAction.performed += OnInteractionE;
|
|
_closeOptionsAction.performed += OnCloseOptions;
|
|
}
|
|
|
|
public override void DisableInput()
|
|
{
|
|
_interactionEAction.performed -= OnInteractionE;
|
|
_closeOptionsAction.performed -= OnCloseOptions;
|
|
}
|
|
|
|
public void SetMasterVolume(float value)
|
|
{
|
|
_audioManager.SetMasterVolume(value);
|
|
_masterVolume.value = value;
|
|
ES3.Save("MasterVolume", value);
|
|
}
|
|
|
|
public void SetBgmVolume(float value)
|
|
{
|
|
_audioManager.SetBgmVolume(value);
|
|
_bgmVolume.value = value;
|
|
ES3.Save("BgmVolume", value);
|
|
}
|
|
|
|
public void SetSfxVolume(float value)
|
|
{
|
|
_audioManager.SetSfxVolume(value);
|
|
_sfxVolume.value = value;
|
|
ES3.Save("SfxVolume", value);
|
|
}
|
|
|
|
private IEnumerator InitializeLanguage()
|
|
{
|
|
yield return new WaitUntil(() => LocalizationManager.Instance.IsInitialized);
|
|
|
|
var languageIndex = LocalizationManager.Instance.GetCurrentLocaleIndex();
|
|
_languageDropdown.value = languageIndex;
|
|
}
|
|
|
|
public void ChangeLanguage(int localeType)
|
|
{
|
|
_languageDropdown.value = localeType;
|
|
LocalizationManager.Instance.ChangeLocale((LocaleType)localeType);
|
|
}
|
|
|
|
public void OnInteractionE(InputAction.CallbackContext context)
|
|
{
|
|
var current = EventSystem.current.currentSelectedGameObject;
|
|
if (!current) return;
|
|
|
|
var currenButton = current.GetComponent<Button>();
|
|
currenButton.onClick.Invoke();
|
|
}
|
|
|
|
public void OnCloseOptions(InputAction.CallbackContext context)
|
|
{
|
|
CloseOptions?.Invoke();
|
|
}
|
|
} |