332 lines
10 KiB
C#
332 lines
10 KiB
C#
using System.Collections;
|
|
using BlueWater.Audios;
|
|
using BlueWater.Uis;
|
|
using BlueWater.Utility;
|
|
using TMPro;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.InputSystem;
|
|
using UnityEngine.Serialization;
|
|
using UnityEngine.UI;
|
|
|
|
namespace BlueWater.Titles
|
|
{
|
|
public class TycoonTitle : PausePopupUi
|
|
{
|
|
[SerializeField]
|
|
private GameObject _panel;
|
|
|
|
[SerializeField]
|
|
private GameObject _titleMenuUiPanel;
|
|
|
|
[SerializeField]
|
|
private TitleOptions titleOptions;
|
|
|
|
[FormerlySerializedAs("titleQuit")]
|
|
[SerializeField]
|
|
private TitleQuitUi titleQuitUi;
|
|
|
|
[SerializeField]
|
|
private Button _startGameButton;
|
|
|
|
[SerializeField]
|
|
private Button _tutorialButton;
|
|
|
|
[SerializeField]
|
|
private Button _resumeGameButton;
|
|
|
|
[SerializeField]
|
|
private Button _optionsButton;
|
|
|
|
[SerializeField]
|
|
private Button _lobbyButton;
|
|
|
|
[SerializeField]
|
|
private Button _quitGameButton;
|
|
|
|
[SerializeField]
|
|
private bool _isTitleScene = true;
|
|
|
|
[SerializeField]
|
|
private TMP_Text _versionText;
|
|
|
|
[SerializeField]
|
|
private string _dailyBgm = "DailyBgm1";
|
|
|
|
[SerializeField]
|
|
private Image _ink;
|
|
|
|
[SerializeField]
|
|
private UiEventsController _uiEventsController;
|
|
|
|
[SerializeField]
|
|
private TycoonTutorial _tycoonTutorial;
|
|
|
|
public Material inkMaterialInstance { get; private set; }
|
|
|
|
private PlayerInputKeyManager _playerInputKeyManager;
|
|
private InputAction _interactionEAction;
|
|
private InputAction _openAction;
|
|
private InputAction _closeAction;
|
|
private GameObject _previousClickedObject;
|
|
private bool _isQuitting;
|
|
private bool _onButtonClicked;
|
|
|
|
private Coroutine _inkCoroutine;
|
|
|
|
private void Start()
|
|
{
|
|
_playerInputKeyManager = PlayerInputKeyManager.Instance;
|
|
_interactionEAction = _playerInputKeyManager.GetAction(InputActionMaps.TycoonUi, TycoonUiActions.InteractionE);
|
|
_openAction = _playerInputKeyManager.GetAction(InputActionMaps.Tycoon, TycoonActions.Options);
|
|
_closeAction = _playerInputKeyManager.GetAction(InputActionMaps.TycoonUi, TycoonUiActions.Cancel);
|
|
|
|
EventManager.OnTutorial += ShowTutorialUiByName;
|
|
|
|
if (_isTitleScene)
|
|
{
|
|
_startGameButton.onClick.AddListener(() => SceneController.Instance.LoadScene(SceneName.Tycoon));
|
|
//수정
|
|
AudioManager.Instance.PlayBgm(_dailyBgm);
|
|
|
|
Open();
|
|
// EventSystem.current.SetSelectedGameObject(_startGameButton.gameObject);
|
|
}
|
|
else
|
|
{
|
|
_lobbyButton.onClick.AddListener(() => SceneController.Instance.LoadScene(SceneName.TycoonTile));
|
|
_panel.SetActive(false);
|
|
_openAction.performed += OnOpen;
|
|
}
|
|
|
|
titleOptions.CloseOptions = HideSettingUi;
|
|
titleQuitUi.CloseQuit = HideQuitUi;
|
|
_tycoonTutorial.CloseAction = HideTutorialUi;
|
|
_versionText.text = GetVersion();
|
|
|
|
inkMaterialInstance = Instantiate(_ink.material);
|
|
_ink.material = inkMaterialInstance;
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
EventManager.OnTutorial -= ShowTutorialUiByName;
|
|
|
|
if (_isTitleScene)
|
|
{
|
|
_startGameButton?.onClick.RemoveListener(() => SceneController.Instance?.LoadScene(SceneName.Tycoon));
|
|
}
|
|
else
|
|
{
|
|
_lobbyButton?.onClick.AddListener(() => SceneController.Instance?.LoadScene(SceneName.TycoonTile));
|
|
}
|
|
|
|
if (_interactionEAction != null)
|
|
{
|
|
_interactionEAction.performed -= OnInteractionE;
|
|
}
|
|
if (_openAction != null)
|
|
{
|
|
_openAction.performed -= OnOpen;
|
|
}
|
|
if (_closeAction != null)
|
|
{
|
|
_closeAction.performed -= OnClose;
|
|
}
|
|
}
|
|
|
|
public void OnOpen(InputAction.CallbackContext context)
|
|
{
|
|
Open();
|
|
}
|
|
|
|
public override void Open()
|
|
{
|
|
OpenSwitch(InputActionMaps.TycoonUi);
|
|
_panel.SetActive(true);
|
|
|
|
// if (_isTitleScene)
|
|
// {
|
|
//
|
|
// }
|
|
// else
|
|
// {
|
|
// VisualFeedbackManager.Instance.SetBaseTimeScale(0f);
|
|
// _playerInputKeyManager.SwitchCurrentActionMap(InputActionMaps.TycoonUi);
|
|
// // EventSystem.current.SetSelectedGameObject(_resumeGameButton.gameObject);
|
|
// }
|
|
}
|
|
|
|
public void OnClose(InputAction.CallbackContext context)
|
|
{
|
|
Close();
|
|
}
|
|
|
|
public override void Close()
|
|
{
|
|
// base.Close();
|
|
//
|
|
// if (_isTitleScene)
|
|
// {
|
|
//
|
|
// }
|
|
// else
|
|
// {
|
|
// if (PopupUiController.IsPopupListEmpty() || !PopupUiController.IsPausedPopupList())
|
|
// {
|
|
// VisualFeedbackManager.Instance.ResetTimeScale();
|
|
// _playerInputKeyManager.SwitchCurrentActionMap(InputActionMaps.Tycoon);
|
|
// }
|
|
// }
|
|
_panel.SetActive(false);
|
|
CloseSwitch(InputActionMaps.Tycoon);
|
|
}
|
|
|
|
public override void EnableInput()
|
|
{
|
|
if (_isTitleScene)
|
|
{
|
|
_uiEventsController.EnableAutoNavigate(_startGameButton.gameObject);
|
|
}
|
|
else
|
|
{
|
|
_uiEventsController.EnableAutoNavigate(_resumeGameButton.gameObject);
|
|
_closeAction.performed += OnClose;
|
|
}
|
|
|
|
_interactionEAction.performed += OnInteractionE;
|
|
}
|
|
|
|
public override void DisableInput()
|
|
{
|
|
if (_isTitleScene)
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
_closeAction.performed -= OnClose;
|
|
}
|
|
|
|
_interactionEAction.performed -= OnInteractionE;
|
|
_uiEventsController.DisableAutoNavigate();
|
|
}
|
|
|
|
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
|
|
EditorApplication.isPlaying = false;
|
|
#else
|
|
Application.Quit();
|
|
#endif
|
|
}
|
|
|
|
public void ShowSettingUi()
|
|
{
|
|
_titleMenuUiPanel.SetActive(false);
|
|
titleOptions.Open();
|
|
EventSystem.current.SetSelectedGameObject(null);
|
|
}
|
|
|
|
public void HideSettingUi()
|
|
{
|
|
titleOptions.Close();
|
|
_titleMenuUiPanel.SetActive(true);
|
|
EventSystem.current.SetSelectedGameObject(null);
|
|
// EventSystem.current.SetSelectedGameObject(_optionsButton.gameObject);
|
|
}
|
|
|
|
public void ShowQuitUi()
|
|
{
|
|
_titleMenuUiPanel.SetActive(false);
|
|
titleQuitUi.Open();
|
|
EventSystem.current.SetSelectedGameObject(null);
|
|
|
|
Utils.StartUniqueCoroutine(this, ref _inkCoroutine, MoveInkBackground(1f));
|
|
}
|
|
|
|
public void HideQuitUi()
|
|
{
|
|
titleQuitUi.Close();
|
|
_titleMenuUiPanel.SetActive(true);
|
|
EventSystem.current.SetSelectedGameObject(null);
|
|
// EventSystem.current.SetSelectedGameObject(_quitGameButton.gameObject);
|
|
|
|
Utils.StartUniqueCoroutine(this, ref _inkCoroutine, MoveInkBackground(0.4f));
|
|
}
|
|
|
|
public void ShowTutorialUi()
|
|
{
|
|
_titleMenuUiPanel.SetActive(false);
|
|
_tycoonTutorial.ShowUi(true);
|
|
EventSystem.current.SetSelectedGameObject(null);
|
|
|
|
Utils.StartUniqueCoroutine(this, ref _inkCoroutine, MoveInkBackground(1f));
|
|
}
|
|
|
|
public void HideTutorialUi(bool isMenu)
|
|
{
|
|
if (!isMenu)
|
|
{
|
|
_panel.SetActive(false);
|
|
}
|
|
|
|
_titleMenuUiPanel.SetActive(true);
|
|
EventSystem.current.SetSelectedGameObject(null);
|
|
// EventSystem.current.SetSelectedGameObject(_tutorialButton.gameObject);
|
|
|
|
Utils.StartUniqueCoroutine(this, ref _inkCoroutine, MoveInkBackground(0.4f));
|
|
}
|
|
|
|
public void ShowTutorialUiByName(string tutorialName)
|
|
{
|
|
_titleMenuUiPanel.SetActive(false);
|
|
_tycoonTutorial.ShowUiByName(tutorialName);
|
|
_panel.SetActive(true);
|
|
|
|
Utils.StartUniqueCoroutine(this, ref _inkCoroutine, MoveInkBackground(1f));
|
|
}
|
|
|
|
private IEnumerator MoveInkBackground(float pos)
|
|
{
|
|
|
|
float timer = 0f;
|
|
var orgPos = inkMaterialInstance.GetFloat("_Position"); // 기존 _Position 값 가져오기.
|
|
|
|
while (timer < 0.3f)
|
|
{
|
|
timer += Time.unscaledDeltaTime;
|
|
|
|
float t = timer / 0.8f;
|
|
float easedT = EaseEffect.ExpoOut(t);
|
|
|
|
// Lerp로 계산한 값을 SetFloat으로 설정.
|
|
inkMaterialInstance.SetFloat("_Position", Mathf.Lerp(orgPos, pos, easedT));
|
|
|
|
yield return null;
|
|
}
|
|
|
|
// 마지막에 정확히 목표값 설정.
|
|
inkMaterialInstance.SetFloat("_Position", pos);
|
|
}
|
|
}
|
|
} |