CapersProject/Assets/02.Scripts/Ui/Title/TycoonTitle.cs

303 lines
8.7 KiB
C#
Raw Normal View History

2024-11-19 12:53:00 +00:00
using System.Collections;
2024-10-08 06:12:27 +00:00
using BlueWater.Audios;
2024-11-18 03:51:28 +00:00
using BlueWater.Uis;
2024-11-30 11:53:38 +00:00
using BlueWater.Utility;
2024-10-08 06:12:27 +00:00
using TMPro;
using UnityEditor;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
2024-11-30 11:53:38 +00:00
using UnityEngine.Serialization;
2024-10-08 06:12:27 +00:00
using UnityEngine.UI;
namespace BlueWater.Titles
{
2024-11-18 03:51:28 +00:00
public class TycoonTitle : PopupUi
2024-10-08 06:12:27 +00:00
{
2024-11-18 03:51:28 +00:00
[SerializeField]
private GameObject _panel;
2024-11-11 12:23:27 +00:00
[SerializeField]
private GameObject _titleMenuUiPanel;
[SerializeField]
2024-11-18 03:51:28 +00:00
private TitleOptions titleOptions;
2024-11-11 12:23:27 +00:00
2024-11-30 11:53:38 +00:00
[FormerlySerializedAs("titleQuit")]
2024-11-19 12:53:00 +00:00
[SerializeField]
2024-11-30 11:53:38 +00:00
private TitleQuitUi titleQuitUi;
2024-11-19 12:53:00 +00:00
2024-10-08 06:12:27 +00:00
[SerializeField]
private Button _startGameButton;
2024-11-11 12:23:27 +00:00
2024-12-16 12:06:42 +00:00
[SerializeField]
private Button _tutorialButton;
2024-10-31 12:17:10 +00:00
[SerializeField]
2024-11-19 07:57:05 +00:00
private Button _resumeGameButton;
2024-11-11 12:23:27 +00:00
2024-10-31 12:17:10 +00:00
[SerializeField]
2024-11-19 07:57:05 +00:00
private Button _optionsButton;
[SerializeField]
private Button _lobbyButton;
[SerializeField]
private Button _quitGameButton;
2024-11-18 03:51:28 +00:00
[SerializeField]
private bool _isTitleScene = true;
2024-10-08 06:12:27 +00:00
[SerializeField]
private TMP_Text _versionText;
[SerializeField]
2024-10-31 12:17:10 +00:00
private string _dailyBgm = "DailyBgm1";
2024-11-19 13:48:41 +00:00
2024-11-19 12:53:00 +00:00
[SerializeField]
2024-11-19 13:48:41 +00:00
private Image _ink;
2024-12-16 12:06:42 +00:00
[SerializeField]
private UiEventsController _uiEventsController;
[SerializeField]
private TycoonTutorial _tycoonTutorial;
2024-11-30 11:53:38 +00:00
2024-11-19 14:19:54 +00:00
public Material inkMaterialInstance { get; private set; }
2024-11-30 11:53:38 +00:00
2024-11-19 13:32:43 +00:00
private PlayerInputKeyManager _playerInputKeyManager;
2024-11-17 04:29:57 +00:00
private InputAction _interactionEAction;
2024-11-18 03:51:28 +00:00
private InputAction _openAction;
private InputAction _closeAction;
2024-11-30 11:53:38 +00:00
private GameObject _previousClickedObject;
2024-11-17 04:29:57 +00:00
private bool _isQuitting;
2024-11-18 03:51:28 +00:00
private bool _onButtonClicked;
2024-11-30 11:53:38 +00:00
private Coroutine _inkCoroutine;
2024-11-19 12:53:00 +00:00
2024-10-08 06:12:27 +00:00
private void Start()
{
2024-11-19 13:32:43 +00:00
_playerInputKeyManager = PlayerInputKeyManager.Instance;
_interactionEAction = _playerInputKeyManager.GetAction(InputActionMaps.TycoonUi, TycoonUiActions.InteractionE);
_openAction = _playerInputKeyManager.GetAction(InputActionMaps.Tycoon, TycoonActions.Options);
_closeAction = _playerInputKeyManager.GetAction(InputActionMaps.TycoonUi, TycoonUiActions.Cancel);
2024-10-31 12:17:10 +00:00
2024-11-18 03:51:28 +00:00
if (_isTitleScene)
{
2024-11-30 11:53:38 +00:00
_startGameButton.onClick.AddListener(() => SceneController.Instance.LoadScene(SceneName.Tycoon));
2024-11-19 13:33:54 +00:00
//수정
2024-11-18 03:51:28 +00:00
AudioManager.Instance.PlayBgm(_dailyBgm);
Open();
2024-11-30 11:53:38 +00:00
EventSystem.current.SetSelectedGameObject(_startGameButton.gameObject);
2024-11-18 03:51:28 +00:00
}
else
{
2024-11-30 11:53:38 +00:00
_lobbyButton.onClick.AddListener(() => SceneController.Instance.LoadScene(SceneName.TycoonTile));
2024-11-18 03:51:28 +00:00
_panel.SetActive(false);
_openAction.performed += OnOpen;
}
2024-11-19 07:57:05 +00:00
titleOptions.CloseOptions = HideSettingUi;
2024-11-30 11:53:38 +00:00
titleQuitUi.CloseQuit = HideQuitUi;
2024-11-18 03:51:28 +00:00
_versionText.text = GetVersion();
2024-11-19 13:48:41 +00:00
2024-11-19 14:19:54 +00:00
inkMaterialInstance = Instantiate(_ink.material);
_ink.material = inkMaterialInstance;
2024-10-31 12:17:10 +00:00
}
2024-11-18 03:51:28 +00:00
private void OnDestroy()
2024-11-17 04:29:57 +00:00
{
2024-11-18 03:51:28 +00:00
if (_isTitleScene)
{
2024-11-30 11:53:38 +00:00
_startGameButton?.onClick.RemoveListener(() => SceneController.Instance?.LoadScene(SceneName.Tycoon));
2024-11-18 03:51:28 +00:00
}
2024-11-30 11:53:38 +00:00
else
2024-11-19 13:32:43 +00:00
{
2024-11-30 11:53:38 +00:00
_lobbyButton?.onClick.AddListener(() => SceneController.Instance?.LoadScene(SceneName.TycoonTile));
2024-11-19 13:32:43 +00:00
}
2024-12-03 09:38:19 +00:00
2024-12-03 12:30:09 +00:00
if (_interactionEAction != null)
{
_interactionEAction.performed -= OnInteractionE;
}
if (_openAction != null)
{
_openAction.performed -= OnOpen;
}
if (_closeAction != null)
{
_closeAction.performed -= OnClose;
}
2024-10-31 12:17:10 +00:00
}
2024-11-18 03:51:28 +00:00
public void OnOpen(InputAction.CallbackContext context)
2024-10-31 12:17:10 +00:00
{
2024-11-18 03:51:28 +00:00
Open();
}
public override void Open()
{
2024-11-30 11:53:38 +00:00
PopupUiController.RegisterPopup(this);
_panel.SetActive(true);
if (_isTitleScene)
{
}
else
2024-11-18 03:51:28 +00:00
{
VisualFeedbackManager.Instance.SetBaseTimeScale(0.0f);
2024-11-30 11:53:38 +00:00
_playerInputKeyManager.SwitchCurrentActionMap(InputActionMaps.TycoonUi);
EventSystem.current.SetSelectedGameObject(_resumeGameButton.gameObject);
2024-11-18 03:51:28 +00:00
}
2024-11-19 07:57:05 +00:00
IsOpened = true;
2024-11-18 03:51:28 +00:00
}
public void OnClose(InputAction.CallbackContext context)
{
Close();
2024-10-08 06:12:27 +00:00
}
2024-11-18 03:51:28 +00:00
public override void Close()
2024-11-19 07:57:05 +00:00
{
2024-11-30 11:53:38 +00:00
_panel.SetActive(false);
PopupUiController.UnregisterPopup(this);
IsOpened = false;
if (_isTitleScene)
{
}
else
2024-11-19 07:57:05 +00:00
{
2024-11-19 13:32:43 +00:00
_playerInputKeyManager.SwitchCurrentActionMap(InputActionMaps.Tycoon);
2024-11-19 07:57:05 +00:00
VisualFeedbackManager.Instance.ResetTimeScale();
}
}
public override void EnableInput()
{
if (_isTitleScene)
{
2024-12-16 12:06:42 +00:00
_uiEventsController.EnableAutoNavigate(_startGameButton.gameObject);
2024-11-19 07:57:05 +00:00
}
else
{
2024-12-16 12:06:42 +00:00
_uiEventsController.EnableAutoNavigate(_resumeGameButton.gameObject);
2024-11-19 07:57:05 +00:00
_closeAction.performed += OnClose;
}
_interactionEAction.performed += OnInteractionE;
}
public override void DisableInput()
2024-10-08 06:12:27 +00:00
{
2024-11-18 03:51:28 +00:00
if (_isTitleScene)
{
}
else
{
_closeAction.performed -= OnClose;
}
2024-11-17 04:29:57 +00:00
_interactionEAction.performed -= OnInteractionE;
2024-12-16 12:06:42 +00:00
_uiEventsController.DisableAutoNavigate();
2024-10-08 06:12:27 +00:00
}
private string GetVersion()
{
#if UNITY_EDITOR
return PlayerSettings.bundleVersion;
#else
return Application.version;
#endif
}
2024-11-17 04:29:57 +00:00
public void OnInteractionE(InputAction.CallbackContext context)
2024-10-08 06:12:27 +00:00
{
2024-11-17 04:29:57 +00:00
var current = EventSystem.current.currentSelectedGameObject;
if (!current) return;
2024-10-08 06:12:27 +00:00
2024-11-17 04:29:57 +00:00
var currenButton = current.GetComponent<Button>();
2024-11-30 11:53:38 +00:00
currenButton?.onClick?.Invoke();
2024-10-08 06:12:27 +00:00
}
public void QuitGame()
{
#if UNITY_EDITOR
2024-11-18 03:51:28 +00:00
EditorApplication.isPlaying = false;
2024-10-08 06:12:27 +00:00
#else
Application.Quit();
#endif
}
2024-11-17 04:29:57 +00:00
public void ShowSettingUi()
{
_titleMenuUiPanel.SetActive(false);
2024-11-19 07:57:05 +00:00
titleOptions.Open();
2024-11-17 04:29:57 +00:00
}
public void HideSettingUi()
{
2024-11-19 07:57:05 +00:00
titleOptions.Close();
2024-11-17 04:29:57 +00:00
_titleMenuUiPanel.SetActive(true);
2024-11-30 11:53:38 +00:00
EventSystem.current.SetSelectedGameObject(_optionsButton.gameObject);
2024-11-18 03:51:28 +00:00
}
2024-11-19 12:53:00 +00:00
public void ShowQuitUi()
{
_titleMenuUiPanel.SetActive(false);
2024-11-30 11:53:38 +00:00
titleQuitUi.Open();
2024-11-19 13:33:54 +00:00
2024-11-30 11:53:38 +00:00
Utils.StartUniqueCoroutine(this, ref _inkCoroutine, MoveInkBackground(1f));
2024-11-19 12:53:00 +00:00
}
public void HideQuitUi()
{
2024-11-30 11:53:38 +00:00
titleQuitUi.Close();
2024-11-19 12:53:00 +00:00
_titleMenuUiPanel.SetActive(true);
2024-11-30 11:53:38 +00:00
EventSystem.current.SetSelectedGameObject(_quitGameButton.gameObject);
2024-11-19 13:33:54 +00:00
2024-11-30 11:53:38 +00:00
Utils.StartUniqueCoroutine(this, ref _inkCoroutine, MoveInkBackground(0.4f));
2024-11-19 12:53:00 +00:00
}
2024-12-16 12:06:42 +00:00
public void ShowTutorialUi()
{
_titleMenuUiPanel.SetActive(false);
_tycoonTutorial.ShowUi();
}
public void HideTutorialUi()
{
_titleMenuUiPanel.SetActive(true);
_tycoonTutorial.HideUi();
EventSystem.current.SetSelectedGameObject(_tutorialButton.gameObject);
}
2024-11-19 13:33:54 +00:00
private IEnumerator MoveInkBackground(float pos)
{
2024-11-19 12:53:00 +00:00
float timer = 0f;
2024-11-19 14:19:54 +00:00
var orgPos = inkMaterialInstance.GetFloat("_Position"); // 기존 _Position 값 가져오기.
2024-11-19 12:53:00 +00:00
2024-11-19 13:33:54 +00:00
while (timer < 0.3f)
2024-11-19 12:53:00 +00:00
{
timer += Time.unscaledDeltaTime;
2024-11-19 13:33:54 +00:00
float t = timer / 0.8f;
2024-11-19 12:53:00 +00:00
float easedT = EaseEffect.ExpoOut(t);
// Lerp로 계산한 값을 SetFloat으로 설정.
2024-11-19 14:19:54 +00:00
inkMaterialInstance.SetFloat("_Position", Mathf.Lerp(orgPos, pos, easedT));
2024-11-19 12:53:00 +00:00
yield return null;
}
// 마지막에 정확히 목표값 설정.
2024-11-19 14:19:54 +00:00
inkMaterialInstance.SetFloat("_Position", pos);
2024-11-19 12:53:00 +00:00
}
2024-10-08 06:12:27 +00:00
}
}