310 lines
8.7 KiB
C#
310 lines
8.7 KiB
C#
using System.Collections;
|
|
using BlueWater.Audios;
|
|
using BlueWater.Uis;
|
|
using TMPro;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.InputSystem;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
|
|
namespace BlueWater.Titles
|
|
{
|
|
public class TycoonTitle : PopupUi
|
|
{
|
|
[SerializeField]
|
|
private GameObject _panel;
|
|
|
|
[SerializeField]
|
|
private GameObject _titleMenuUiPanel;
|
|
|
|
[SerializeField]
|
|
private TitleOptions titleOptions;
|
|
|
|
[SerializeField]
|
|
private TitleQuit titleQuit;
|
|
|
|
[SerializeField]
|
|
private Button _startGameButton;
|
|
|
|
[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]
|
|
public Material _backgroundInkMaterial;
|
|
|
|
private PlayerInputKeyManager _playerInputKeyManager;
|
|
private SceneController _sceneController;
|
|
private InputAction _interactionEAction;
|
|
private InputAction _openAction;
|
|
private InputAction _closeAction;
|
|
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);
|
|
|
|
if (_isTitleScene)
|
|
{
|
|
_sceneController = SceneController.Instance;
|
|
_startGameButton.onClick.AddListener(_sceneController.FadeIn);
|
|
//수정
|
|
AudioManager.Instance.PlayBgm(_dailyBgm);
|
|
|
|
Open();
|
|
}
|
|
else
|
|
{
|
|
_panel.SetActive(false);
|
|
_openAction.performed += OnOpen;
|
|
}
|
|
|
|
_startGameButton?.onClick.AddListener(() => { _onButtonClicked = true; });
|
|
_resumeGameButton?.onClick.AddListener(() => { _onButtonClicked = true; });
|
|
_optionsButton?.onClick.AddListener(() => { _onButtonClicked = true; });
|
|
_lobbyButton?.onClick.AddListener(() => { _onButtonClicked = true; });
|
|
_quitGameButton?.onClick.AddListener(() => { _onButtonClicked = true; });
|
|
|
|
_playerInputKeyManager.AddOnActionKeyboard(OnKeyboard);
|
|
_playerInputKeyManager.AddOnActionMouse(OnMouse);
|
|
|
|
titleOptions.CloseOptions = HideSettingUi;
|
|
titleQuit.CloseQuit = HideQuitUi;
|
|
_versionText.text = GetVersion();
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (_isTitleScene)
|
|
{
|
|
if (_startGameButton != null && _sceneController != null)
|
|
{
|
|
_startGameButton.onClick.RemoveListener(_sceneController.FadeIn);
|
|
//수정
|
|
}
|
|
}
|
|
|
|
if (_playerInputKeyManager != null)
|
|
{
|
|
_playerInputKeyManager.RemoveOnActionKeyboard(OnKeyboard);
|
|
_playerInputKeyManager.RemoveOnActionMouse(OnMouse);
|
|
}
|
|
|
|
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()
|
|
{
|
|
if (!_isTitleScene)
|
|
{
|
|
VisualFeedbackManager.Instance.SetBaseTimeScale(0.0f);
|
|
}
|
|
|
|
_playerInputKeyManager.SwitchCurrentActionMap(InputActionMaps.TycoonUi);
|
|
PopupUiController.RegisterPopup(this);
|
|
_panel.SetActive(true);
|
|
IsOpened = true;
|
|
}
|
|
|
|
public void OnClose(InputAction.CallbackContext context)
|
|
{
|
|
Close();
|
|
}
|
|
|
|
public override void Close()
|
|
{
|
|
if (!_isTitleScene)
|
|
{
|
|
_panel.SetActive(false);
|
|
PopupUiController.UnregisterPopup(this);
|
|
_playerInputKeyManager.SwitchCurrentActionMap(InputActionMaps.Tycoon);
|
|
IsOpened = false;
|
|
VisualFeedbackManager.Instance.ResetTimeScale();
|
|
}
|
|
}
|
|
|
|
public override void EnableInput()
|
|
{
|
|
if (_isTitleScene)
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
_closeAction.performed += OnClose;
|
|
}
|
|
|
|
_interactionEAction.performed += OnInteractionE;
|
|
}
|
|
|
|
public override void DisableInput()
|
|
{
|
|
if (_isTitleScene)
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
_closeAction.performed -= OnClose;
|
|
}
|
|
|
|
_interactionEAction.performed -= OnInteractionE;
|
|
}
|
|
|
|
private void OnKeyboard()
|
|
{
|
|
if (_isTitleScene)
|
|
{
|
|
EventSystem.current.SetSelectedGameObject(_startGameButton.gameObject);
|
|
}
|
|
else
|
|
{
|
|
EventSystem.current.SetSelectedGameObject(_resumeGameButton.gameObject);
|
|
}
|
|
}
|
|
|
|
private void OnMouse()
|
|
{
|
|
if (!_onButtonClicked)
|
|
{
|
|
EventSystem.current.SetSelectedGameObject(null);
|
|
}
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
public void HideSettingUi()
|
|
{
|
|
titleOptions.Close();
|
|
_titleMenuUiPanel.SetActive(true);
|
|
}
|
|
|
|
|
|
public void ShowQuitUi()
|
|
{
|
|
_titleMenuUiPanel.SetActive(false);
|
|
titleQuit.Open();
|
|
|
|
if (_InkCoroutine != null)
|
|
{
|
|
StopCoroutine(_InkCoroutine);
|
|
}
|
|
|
|
_InkCoroutine = StartCoroutine(MoveInkBackground(1.0f));
|
|
|
|
}
|
|
|
|
public void HideQuitUi()
|
|
{
|
|
titleQuit.Close();
|
|
_titleMenuUiPanel.SetActive(true);
|
|
|
|
if (_InkCoroutine != null)
|
|
{
|
|
StopCoroutine(_InkCoroutine);
|
|
}
|
|
|
|
_InkCoroutine = StartCoroutine(MoveInkBackground(0.4f));
|
|
}
|
|
|
|
private IEnumerator MoveInkBackground(float pos)
|
|
{
|
|
|
|
float timer = 0f;
|
|
var orgPos = _backgroundInkMaterial.GetFloat("_Position"); // 기존 _Position 값 가져오기.
|
|
|
|
while (timer < 0.3f)
|
|
{
|
|
timer += Time.unscaledDeltaTime;
|
|
|
|
float t = timer / 0.8f;
|
|
float easedT = EaseEffect.ExpoOut(t);
|
|
|
|
// Lerp로 계산한 값을 SetFloat으로 설정.
|
|
_backgroundInkMaterial.SetFloat("_Position", Mathf.Lerp(orgPos, pos, easedT));
|
|
|
|
yield return null;
|
|
}
|
|
|
|
// 마지막에 정확히 목표값 설정.
|
|
_backgroundInkMaterial.SetFloat("_Position", pos);
|
|
}
|
|
|
|
public void MoveLobbyScene()
|
|
{
|
|
SceneManager.LoadScene("00.TycoonTitle");
|
|
}
|
|
}
|
|
} |