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

157 lines
5.2 KiB
C#
Raw Normal View History

2024-11-17 04:29:57 +00:00
using System.Collections;
using BlueWater.Items;
using UnityEngine;
using UnityEngine.UI;
2024-12-10 09:56:18 +00:00
using Spine.Unity;
2024-12-12 06:30:38 +00:00
using UnityEngine.InputSystem;
2024-11-17 04:29:57 +00:00
namespace BlueWater.Uis
{
public class UpgradePopupUi : PopupUi
{
[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()
{
VisualFeedbackManager.Instance.SetBaseTimeScale(0.0f);
PlayerInputKeyManager.Instance.SwitchCurrentActionMap(InputActionMaps.TycoonUi);
PopupUiController.RegisterPopup(this);
_panel.SetActive(true);
IsOpened = true;
}
2024-12-10 09:56:18 +00:00
2024-11-17 04:29:57 +00:00
public override void Close()
{
_panel.SetActive(false);
PopupUiController.UnregisterPopup(this);
PlayerInputKeyManager.Instance.SwitchCurrentActionMap(InputActionMaps.Tycoon);
IsOpened = false;
VisualFeedbackManager.Instance.ResetTimeScale();
}
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-11-17 04:29:57 +00:00
}
}
}