CapersProject/Assets/02.Scripts/Ui/Tycoon/Upgrade_Popup.cs
2024-10-31 14:41:13 +09:00

119 lines
3.0 KiB
C#

using System.Collections;
using BlueWater;
using BlueWater.Uis;
using UnityEngine;
using UnityEngine.UI;
public class Upgrade_Popup : PopupUi
{
[SerializeField]
private GameObject _panel;
[SerializeField]
private AnimationController _animationController;
private bool isReversing = false; // 애니메이션 상태를 체크할 변수
[SerializeField]
private Image information; //정보를 알려주는 이미지
private void Start()
{
EventManager.OnUpgradeUi += StartUpgradePopup;
}
private void OnDestroy()
{
EventManager.OnUpgradeUi -= StartUpgradePopup;
}
public override void Open()
{
VisualFeedbackManager.Instance.SetBaseTimeScale(0.0f);
PlayerInputKeyManager.Instance.DisableAction("Manual");
PopupUiController.RegisterPopup(this);
ShowUi();
IsOpened = true;
}
public override void Close()
{
HideUi();
PlayerInputKeyManager.Instance.EnableAction("Manual");
PopupUiController.UnregisterPopup(this);
IsOpened = false;
if (!PopupUiController.IsPopupListEmpty()) return;
VisualFeedbackManager.Instance.ResetTimeScale();
}
private void StartUpgradePopup(LevelData currentLevelData)
{
StartCoroutine(StartUpgradePopupCoroutine(currentLevelData));
}
// ReSharper disable Unity.PerformanceAnalysis
private IEnumerator StartUpgradePopupCoroutine(LevelData currentLevelData)
{
Open();
float timer = 0f;
while (timer < 1.0f)
{
timer += Time.unscaledDeltaTime;
yield return null;
}
timer = 0f;
while (timer < 0.5)
{
timer += Time.unscaledDeltaTime;
float t = timer / 0.5f;
float easedT = EaseEffect.BounceOut(t);
information.transform.localScale = Vector3.Lerp( new Vector3(0.0f,0.0f,0.0f), new Vector3(1.0f,1.0f,1.0f), easedT);
yield return null;
}
timer = 0f;
while (timer < 2.0)
{
timer += Time.unscaledDeltaTime;
yield return null;
}
timer = 0f;
while (timer < 0.5)
{
timer += Time.unscaledDeltaTime;
float t = timer / 0.5f;
float easedT = EaseEffect.BounceOut(t);
information.transform.localScale = Vector3.Lerp( new Vector3(1.0f,1.0f,1.0f), new Vector3(0.0f,0.0f,0.0f), easedT);
yield return null;
}
_animationController.PlayAnimation("CardUpgrade_Reverse");
timer = 0f;
while (timer < 1.0f)
{
timer += Time.unscaledDeltaTime;
yield return null;
}
VisualFeedbackManager.Instance.ResetTimeScale();
Close();
}
public void ShowUi() => _panel.SetActive(true);
public void HideUi() => _panel.SetActive(false);
}