157 lines
5.2 KiB
C#
157 lines
5.2 KiB
C#
using System.Collections;
|
|
using BlueWater.Items;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using Spine.Unity;
|
|
using UnityEngine.InputSystem;
|
|
|
|
namespace BlueWater.Uis
|
|
{
|
|
public class UpgradePopupUi : PopupUi
|
|
{
|
|
[SerializeField]
|
|
private GameObject _panel;
|
|
|
|
[SerializeField]
|
|
private SkeletonGraphic _paperAnimation;
|
|
|
|
[SerializeField]
|
|
private GameObject _information; //정보를 알려주는 이미지
|
|
|
|
[SerializeField]
|
|
private GameObject _tableInformation; //정보를 알려주는 이미지
|
|
|
|
[SerializeField]
|
|
private GameObject _ingredientInformation; //정보를 알려주는 이미지
|
|
|
|
[SerializeField]
|
|
private Image _liquidImage; //재료 이미지
|
|
|
|
[SerializeField]
|
|
private Button _closeButton;
|
|
|
|
private InputAction _interactionEAction;
|
|
|
|
private void Start()
|
|
{
|
|
EventManager.OnLevelUp += StartUpgradePopup;
|
|
|
|
_interactionEAction = PlayerInputKeyManager.Instance.GetAction(InputActionMaps.TycoonUi, TycoonUiActions.InteractionE);
|
|
|
|
_information.transform.localScale = Vector3.zero;
|
|
_closeButton.gameObject.SetActive(false);
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
public override void Close()
|
|
{
|
|
_panel.SetActive(false);
|
|
PopupUiController.UnregisterPopup(this);
|
|
PlayerInputKeyManager.Instance.SwitchCurrentActionMap(InputActionMaps.Tycoon);
|
|
IsOpened = false;
|
|
VisualFeedbackManager.Instance.ResetTimeScale();
|
|
}
|
|
|
|
public override void DisableInput()
|
|
{
|
|
_interactionEAction.performed -= OnInteractionE;
|
|
}
|
|
|
|
public void OnInteractionE(InputAction.CallbackContext context)
|
|
{
|
|
_closeButton.onClick?.Invoke();
|
|
}
|
|
|
|
private void StartUpgradePopup(LevelData currentLevelData)
|
|
{
|
|
if (string.IsNullOrEmpty(currentLevelData.OpenUpgrade)) return;
|
|
|
|
int currentLevel = int.Parse(currentLevelData.Idx);
|
|
_liquidImage.sprite = currentLevel switch
|
|
{
|
|
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,
|
|
_ => _liquidImage.sprite
|
|
};
|
|
|
|
_ingredientInformation.SetActive(currentLevel != 35);
|
|
|
|
Open();
|
|
var trackEntry = _paperAnimation.AnimationState.SetAnimation(0, "Idle", false);
|
|
//trackEntry.TimeScale = Time.unscaledDeltaTime * 15f;
|
|
trackEntry.Complete += (track) =>
|
|
{
|
|
StartCoroutine(StartUpgradePopupCoroutine(currentLevelData));
|
|
};
|
|
|
|
}
|
|
|
|
// ReSharper disable Unity.PerformanceAnalysis
|
|
private IEnumerator StartUpgradePopupCoroutine(LevelData currentLevelData)
|
|
{
|
|
_closeButton.gameObject.SetActive(true);
|
|
float 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, 1.0f), new Vector3(1.0f, 1.0f, 1.0f), easedT);
|
|
yield return null;
|
|
}
|
|
|
|
_interactionEAction.performed += OnInteractionE;
|
|
}
|
|
|
|
public void OnCloseButton()
|
|
{
|
|
StartCoroutine(CloseUpgradePopupCoroutine());
|
|
}
|
|
|
|
private IEnumerator CloseUpgradePopupCoroutine()
|
|
{
|
|
_interactionEAction.performed -= OnInteractionE;
|
|
float 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, 1.0f), easedT);
|
|
yield return null;
|
|
}
|
|
|
|
_closeButton.gameObject.SetActive(false);
|
|
|
|
_paperAnimation.AnimationState.SetAnimation(0, "Back", false).Complete += (trackEntry) =>
|
|
{
|
|
Close();
|
|
};
|
|
}
|
|
}
|
|
} |