CapersProject/Assets/02.Scripts/Ui/Tycoon/UpgradePopupUi.cs

194 lines
6.4 KiB
C#
Raw Normal View History

2024-11-17 04:29:57 +00:00
using System.Collections;
using BlueWater.Items;
2024-12-17 11:25:53 +00:00
using BlueWater.Tycoons;
2024-11-17 04:29:57 +00:00
using UnityEngine;
using UnityEngine.UI;
2024-12-10 09:56:18 +00:00
using Spine.Unity;
2024-12-20 05:11:56 +00:00
using UnityEngine.EventSystems;
2024-12-12 06:30:38 +00:00
using UnityEngine.InputSystem;
2024-11-17 04:29:57 +00:00
namespace BlueWater.Uis
{
2024-12-18 16:00:39 +00:00
public class UpgradePopupUi : PausePopupUi
2024-11-17 04:29:57 +00:00
{
[SerializeField]
private GameObject _panel;
2024-12-12 06:30:38 +00:00
2024-11-17 04:29:57 +00:00
[SerializeField]
2024-12-12 06:30:38 +00:00
private SkeletonGraphic _paperAnimation;
2024-11-17 04:29:57 +00:00
[SerializeField]
2024-12-12 06:30:38 +00:00
private GameObject _information; //정보를 알려주는 이미지
2024-12-10 09:56:18 +00:00
2024-11-17 04:29:57 +00:00
[SerializeField]
2024-12-12 06:30:38 +00:00
private GameObject _tableInformation; //정보를 알려주는 이미지
2024-12-10 09:56:18 +00:00
[SerializeField]
2024-12-12 06:30:38 +00:00
private GameObject _ingredientInformation; //정보를 알려주는 이미지
2024-12-10 09:56:18 +00:00
[SerializeField]
2024-12-12 06:30:38 +00:00
private Image _liquidImage; //재료 이미지
2024-12-10 09:56:18 +00:00
[SerializeField]
2024-12-12 06:30:38 +00:00
private Button _closeButton;
private InputAction _interactionEAction;
2024-12-10 09:56:18 +00:00
2024-11-17 04:29:57 +00:00
private void Start()
{
EventManager.OnLevelUp += StartUpgradePopup;
2024-12-12 06:30:38 +00:00
_interactionEAction = PlayerInputKeyManager.Instance.GetAction(InputActionMaps.TycoonUi, TycoonUiActions.InteractionE);
_information.transform.localScale = Vector3.zero;
_closeButton.gameObject.SetActive(false);
2024-11-17 04:29:57 +00:00
}
private void OnDestroy()
{
EventManager.OnLevelUp -= StartUpgradePopup;
}
public override void Open()
{
2024-12-18 16:00:39 +00:00
OpenSwitch(InputActionMaps.TycoonUi);
2024-11-17 04:29:57 +00:00
_panel.SetActive(true);
}
2024-12-10 09:56:18 +00:00
2024-11-17 04:29:57 +00:00
public override void Close()
{
_panel.SetActive(false);
2024-12-18 16:00:39 +00:00
CloseSwitch(InputActionMaps.Tycoon);
2024-12-20 05:11:56 +00:00
EventSystem.current.SetSelectedGameObject(null);
2024-11-17 04:29:57 +00:00
}
2024-12-12 06:30:38 +00:00
public override void DisableInput()
{
_interactionEAction.performed -= OnInteractionE;
}
public void OnInteractionE(InputAction.CallbackContext context)
{
_closeButton.onClick?.Invoke();
}
2024-11-17 04:29:57 +00:00
private void StartUpgradePopup(LevelData currentLevelData)
{
if (string.IsNullOrEmpty(currentLevelData.OpenUpgrade)) return;
2024-12-12 06:30:38 +00:00
int currentLevel = int.Parse(currentLevelData.Idx);
_liquidImage.sprite = currentLevel switch
2024-11-17 04:29:57 +00:00
{
5 => ItemManager.Instance.LiquidDataSo.GetDataByIdx("LiquidB").Sprite,
10 => ItemManager.Instance.LiquidDataSo.GetDataByIdx("LiquidC").Sprite,
15 => ItemManager.Instance.LiquidDataSo.GetDataByIdx("LiquidD").Sprite,
20 => ItemManager.Instance.LiquidDataSo.GetDataByIdx("LiquidE").Sprite,
25 => ItemManager.Instance.LiquidDataSo.GetDataByIdx("Garnish1").Sprite,
30 => ItemManager.Instance.LiquidDataSo.GetDataByIdx("Garnish2").Sprite,
2024-12-12 06:30:38 +00:00
_ => _liquidImage.sprite
2024-11-17 04:29:57 +00:00
};
2024-12-10 09:56:18 +00:00
2024-12-12 06:30:38 +00:00
_ingredientInformation.SetActive(currentLevel != 35);
2024-12-10 09:56:18 +00:00
Open();
2024-12-12 06:30:38 +00:00
var trackEntry = _paperAnimation.AnimationState.SetAnimation(0, "Idle", false);
2024-12-10 09:56:18 +00:00
//trackEntry.TimeScale = Time.unscaledDeltaTime * 15f;
trackEntry.Complete += (track) =>
{
StartCoroutine(StartUpgradePopupCoroutine(currentLevelData));
};
2024-11-17 04:29:57 +00:00
}
// ReSharper disable Unity.PerformanceAnalysis
private IEnumerator StartUpgradePopupCoroutine(LevelData currentLevelData)
{
2024-12-12 06:30:38 +00:00
_closeButton.gameObject.SetActive(true);
2024-11-17 04:29:57 +00:00
float timer = 0f;
while (timer < 0.5)
{
timer += Time.unscaledDeltaTime;
float t = timer / 0.5f;
float easedT = EaseEffect.BounceOut(t);
2024-12-12 06:30:38 +00:00
_information.transform.localScale =
2024-12-10 09:56:18 +00:00
Vector3.Lerp(new Vector3(0.0f, 0.0f, 1.0f), new Vector3(1.0f, 1.0f, 1.0f), easedT);
2024-11-17 04:29:57 +00:00
yield return null;
}
2024-12-12 06:30:38 +00:00
_interactionEAction.performed += OnInteractionE;
2024-12-10 09:56:18 +00:00
}
2024-11-17 04:29:57 +00:00
2024-12-10 09:56:18 +00:00
public void OnCloseButton()
{
StartCoroutine(CloseUpgradePopupCoroutine());
}
private IEnumerator CloseUpgradePopupCoroutine()
{
2024-12-12 06:30:38 +00:00
_interactionEAction.performed -= OnInteractionE;
2024-12-10 09:56:18 +00:00
float timer = 0f;
2024-11-17 04:29:57 +00:00
while (timer < 0.5)
{
timer += Time.unscaledDeltaTime;
float t = timer / 0.5f;
float easedT = EaseEffect.BounceOut(t);
2024-12-12 06:30:38 +00:00
_information.transform.localScale =
2024-12-10 09:56:18 +00:00
Vector3.Lerp(new Vector3(1.0f, 1.0f, 1.0f), new Vector3(0.0f, 0.0f, 1.0f), easedT);
2024-11-17 04:29:57 +00:00
yield return null;
}
2024-12-12 06:30:38 +00:00
_closeButton.gameObject.SetActive(false);
2024-11-17 04:29:57 +00:00
2024-12-12 06:30:38 +00:00
_paperAnimation.AnimationState.SetAnimation(0, "Back", false).Complete += (trackEntry) =>
2024-11-17 04:29:57 +00:00
{
2024-12-10 09:56:18 +00:00
Close();
2024-12-17 11:25:53 +00:00
int currentLevel = int.Parse(TycoonManager.Instance.GetCurrentLevelData().Idx);
if (currentLevel == 5)
{
if (!ES3.Load(SaveData.TutorialG, false))
{
EventManager.InvokeTutorial(TutorialName.TutorialG);
ES3.Save(SaveData.TutorialG, true);
}
if (!ES3.Load(SaveData.TutorialH, false))
{
2024-12-20 05:11:56 +00:00
EventManager.InvokeTutorial(TutorialName.TutorialH);
ES3.Save(SaveData.TutorialH, true);
2024-12-17 11:25:53 +00:00
}
if (!ES3.Load(SaveData.TutorialI, false))
{
2024-12-20 05:11:56 +00:00
EventManager.InvokeTutorial(TutorialName.TutorialI);
ES3.Save(SaveData.TutorialI, true);
2024-12-17 11:25:53 +00:00
}
}
2024-12-10 09:56:18 +00:00
};
2024-11-17 04:29:57 +00:00
}
2024-12-17 11:25:53 +00:00
private void InvokeTutorialH()
{
if (!ES3.Load(SaveData.TutorialH, false))
{
EventManager.InvokeTutorial(TutorialName.TutorialH);
ES3.Save(SaveData.TutorialH, true);
}
}
private void InvokeTutorialI()
{
if (!ES3.Load(SaveData.TutorialI, false))
{
EventManager.InvokeTutorial(TutorialName.TutorialI);
ES3.Save(SaveData.TutorialI, true);
}
}
2024-11-17 04:29:57 +00:00
}
}