144 lines
4.4 KiB
C#
144 lines
4.4 KiB
C#
using BlueWater.Audios;
|
|
using Sirenix.OdinInspector;
|
|
using TMPro;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.InputSystem;
|
|
using UnityEngine.UI;
|
|
|
|
namespace BlueWater.Titles
|
|
{
|
|
public class TycoonTitle : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private GameObject _titleMenuUiPanel;
|
|
|
|
[SerializeField]
|
|
private TitleSetting _titleSetting;
|
|
|
|
[SerializeField]
|
|
private Button _startGameButton;
|
|
|
|
[SerializeField]
|
|
private Button _settingButton;
|
|
|
|
[SerializeField]
|
|
private Button _exitButton;
|
|
|
|
private bool _onButtonClicked;
|
|
|
|
[SerializeField]
|
|
private TMP_Text _versionText;
|
|
|
|
[SerializeField]
|
|
private string _dailyBgm = "DailyBgm1";
|
|
|
|
private InputAction _interactionEAction;
|
|
private InputAction _settingCancelAction;
|
|
private bool _isQuitting;
|
|
|
|
private void Awake()
|
|
{
|
|
InitializeComponents();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
_interactionEAction = PlayerInputKeyManager.Instance.GetAction(InputActionMaps.TycoonUi, "InteractionE");
|
|
_settingCancelAction = PlayerInputKeyManager.Instance.GetAction(InputActionMaps.TycoonUi, "Cancel");
|
|
|
|
AudioManager.Instance.PlayBgm(_dailyBgm);
|
|
_startGameButton.onClick.AddListener(SceneController.Instance.FadeIn);
|
|
|
|
_startGameButton.onClick.AddListener(() => { _onButtonClicked = true; });
|
|
_settingButton.onClick.AddListener(() => { _onButtonClicked = true; });
|
|
_exitButton.onClick.AddListener(() => { _onButtonClicked = true; });
|
|
|
|
PlayerInputKeyManager.Instance.AddOnActionKeyboard(OnKeyboard);
|
|
PlayerInputKeyManager.Instance.AddOnActionMouse(OnMouse);
|
|
|
|
_interactionEAction.performed += OnInteractionE;
|
|
}
|
|
|
|
private void OnKeyboard()
|
|
{
|
|
EventSystem.current.SetSelectedGameObject(_startGameButton.gameObject);
|
|
}
|
|
|
|
private void OnMouse()
|
|
{
|
|
if (!_onButtonClicked)
|
|
{
|
|
EventSystem.current.SetSelectedGameObject(null);
|
|
}
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
_startGameButton.onClick.RemoveListener(SceneController.Instance.FadeIn);
|
|
|
|
PlayerInputKeyManager.Instance.RemoveOnActionKeyboard(OnKeyboard);
|
|
PlayerInputKeyManager.Instance.RemoveOnActionMouse(OnMouse);
|
|
|
|
_interactionEAction.performed -= OnInteractionE;
|
|
_settingCancelAction.performed -= OnSettingCancel;
|
|
}
|
|
|
|
[Button("컴포넌트 초기화")]
|
|
private void InitializeComponents()
|
|
{
|
|
_titleMenuUiPanel = transform.Find("TitleMenuUi/Panel").gameObject;
|
|
_startGameButton = transform.Find("TitleMenuUi/Panel/ButtonPanel/StartGameButton").GetComponent<Button>();
|
|
_titleSetting = transform.Find("TitleSetting").GetComponent<TitleSetting>();
|
|
_versionText = transform.Find("VersionText").GetComponent<TMP_Text>();
|
|
_versionText.text = GetVersion();
|
|
}
|
|
|
|
private string GetVersion()
|
|
{
|
|
#if UNITY_EDITOR
|
|
return PlayerSettings.bundleVersion;
|
|
#else
|
|
return Application.version;
|
|
#endif
|
|
}
|
|
|
|
public void OnInteractionE(InputAction.CallbackContext context)
|
|
{
|
|
var current = EventSystem.current.currentSelectedGameObject;
|
|
if (!current) return;
|
|
|
|
var currenButton = current.GetComponent<Button>();
|
|
currenButton.onClick.Invoke();
|
|
}
|
|
|
|
public void QuitGame()
|
|
{
|
|
#if UNITY_EDITOR
|
|
UnityEditor.EditorApplication.isPlaying = false;
|
|
#else
|
|
Application.Quit();
|
|
#endif
|
|
}
|
|
|
|
public void OnSettingCancel(InputAction.CallbackContext context)
|
|
{
|
|
HideSettingUi();
|
|
}
|
|
|
|
public void ShowSettingUi()
|
|
{
|
|
_titleMenuUiPanel.SetActive(false);
|
|
_titleSetting.ShowUi();
|
|
_settingCancelAction.performed += OnSettingCancel;
|
|
}
|
|
|
|
public void HideSettingUi()
|
|
{
|
|
_settingCancelAction.performed -= OnSettingCancel;
|
|
_titleSetting.HideUi();
|
|
_titleMenuUiPanel.SetActive(true);
|
|
}
|
|
}
|
|
} |