+ 전투 맵 수정 + CombatPlayer MainSkillUi 초기화 오류 수정 + 메뉴UI Close버튼 미작동 수정 + HitStop과 SlowMotion 겹치는 문제 수정
185 lines
6.4 KiB
C#
185 lines
6.4 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
// ReSharper disable once CheckNamespace
|
|
namespace BlueWaterProject
|
|
{
|
|
public class CombatUiManager : Singleton<CombatUiManager>
|
|
{
|
|
[field: Title("UI")]
|
|
[field: SerializeField] public Canvas MainCanvas { get; private set; }
|
|
[field: SerializeField] public Canvas WorldSpaceCanvas { get; private set; }
|
|
[field: SerializeField] public SkillUi MainSkillUi { get; private set; }
|
|
[field: SerializeField] public FieldBossHpSlider FieldBossHpSlider { get; private set; }
|
|
[field: SerializeField] public HeartHpUi HeartHpUi { get; private set; }
|
|
[field: SerializeField] public DropItemGroupController DropItemGroupController { get; private set; }
|
|
[field: SerializeField] public CombatItemInventoryUi CombatItemInventoryUi { get; private set; }
|
|
[field: SerializeField] public GameOverPopupUi GameOverPopupUi { get; private set; }
|
|
[field: SerializeField] public ClearPopupUi ClearPopupUi { get; private set; }
|
|
[field: SerializeField] public CombatMenuPopupUi CombatMenuPopupUi { get; private set; }
|
|
|
|
[Title("효과")]
|
|
[SerializeField] private Image fadeUi;
|
|
[SerializeField] private Vector2 fadeDuration = new(0.2f, 0.3f);
|
|
|
|
private List<PopupUi> popupUiList;
|
|
|
|
protected override void OnAwake()
|
|
{
|
|
Init();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
PopupUi.OnPopupUiOpenEvent += RegisterPopup;
|
|
PopupUi.OnPopupUiCloseEvent += UnregisterPopup;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
PopupUi.OnPopupUiOpenEvent -= RegisterPopup;
|
|
PopupUi.OnPopupUiCloseEvent -= UnregisterPopup;
|
|
}
|
|
|
|
[Button("셋팅 초기화")]
|
|
private void Init()
|
|
{
|
|
MainCanvas = GetComponent<Canvas>();
|
|
if (!MainCanvas)
|
|
{
|
|
Debug.LogError("canvas is null error");
|
|
return;
|
|
}
|
|
|
|
WorldSpaceCanvas = GameObject.Find("WorldSpaceCanvas").GetComponent<Canvas>();
|
|
MainSkillUi = MainCanvas.transform.Find("MainSkillUi").GetComponent<SkillUi>();
|
|
FieldBossHpSlider = MainCanvas.transform.Find("FieldBossHpSlider").GetComponent<FieldBossHpSlider>();
|
|
HeartHpUi = MainCanvas.transform.Find("HeartHpUi").GetComponent<HeartHpUi>();
|
|
DropItemGroupController = MainCanvas.transform.Find("DropItemGroup").GetComponent<DropItemGroupController>();
|
|
CombatItemInventoryUi = MainCanvas.transform.Find("CombatItemInventoryUi").GetComponent<CombatItemInventoryUi>();
|
|
GameOverPopupUi = MainCanvas.transform.Find("GameOverPopupUi").GetComponent<GameOverPopupUi>();
|
|
ClearPopupUi = MainCanvas.transform.Find("ClearPopupUi").GetComponent<ClearPopupUi>();
|
|
CombatMenuPopupUi = MainCanvas.transform.Find("CombatMenuPopupUi").GetComponent<CombatMenuPopupUi>();
|
|
fadeUi = MainCanvas.transform.Find("FadeUi").GetComponent<Image>();
|
|
|
|
popupUiList = new List<PopupUi>(8);
|
|
}
|
|
|
|
private void RegisterPopup(PopupUi popup)
|
|
{
|
|
if (!popupUiList.Contains(popup))
|
|
{
|
|
popupUiList.Add(popup);
|
|
}
|
|
}
|
|
|
|
private void UnregisterPopup(PopupUi popup)
|
|
{
|
|
if (popupUiList.Contains(popup))
|
|
{
|
|
popupUiList.Remove(popup);
|
|
}
|
|
}
|
|
|
|
public void CloseLastPopup()
|
|
{
|
|
if (popupUiList.Count <= 0) return;
|
|
|
|
popupUiList[^1].Close();
|
|
}
|
|
|
|
public void CloseAllPopup()
|
|
{
|
|
var tempList = new List<PopupUi>(popupUiList);
|
|
|
|
foreach (var popup in tempList)
|
|
{
|
|
popup.Close();
|
|
}
|
|
|
|
popupUiList.Clear();
|
|
}
|
|
|
|
public bool IsPopupListEmpty() => popupUiList.Count == 0;
|
|
|
|
public void FadeInOut()
|
|
{
|
|
StartCoroutine(nameof(FadeInOutCoroutine));
|
|
}
|
|
|
|
private IEnumerator FadeInOutCoroutine()
|
|
{
|
|
fadeUi.enabled = true;
|
|
// 페이드 인
|
|
var elapsedTime = 0f;
|
|
while (elapsedTime < fadeDuration.x)
|
|
{
|
|
elapsedTime += Time.deltaTime;
|
|
var alpha = Mathf.Lerp(0f, 1f, elapsedTime / fadeDuration.x);
|
|
fadeUi.color = new Color(fadeUi.color.r, fadeUi.color.g, fadeUi.color.b, alpha);
|
|
yield return null;
|
|
}
|
|
|
|
fadeUi.color = new Color(fadeUi.color.r, fadeUi.color.g, fadeUi.color.b, 1f);
|
|
|
|
// 페이드 아웃
|
|
elapsedTime = 0f;
|
|
while (elapsedTime < fadeDuration.y)
|
|
{
|
|
elapsedTime += Time.deltaTime;
|
|
var alpha = Mathf.Lerp(1f, 0f, elapsedTime / fadeDuration.y);
|
|
fadeUi.color = new Color(fadeUi.color.r, fadeUi.color.g, fadeUi.color.b, alpha);
|
|
yield return null;
|
|
}
|
|
|
|
fadeUi.color = new Color(fadeUi.color.r, fadeUi.color.g, fadeUi.color.b, 0f);
|
|
fadeUi.enabled = false;
|
|
}
|
|
|
|
public void RestartCurrentStage()
|
|
{
|
|
switch (DataManager.Inst.CurrentSaveStage)
|
|
{
|
|
case SaveStage.TUTORIAL:
|
|
break;
|
|
case SaveStage.SLIME:
|
|
FindAnyObjectByType<SlimeBossMapController>()?.InitBossMap();
|
|
break;
|
|
case SaveStage.RHINOCEROS:
|
|
FindAnyObjectByType<RhinocerosBossMapController>()?.InitBossMap();
|
|
break;
|
|
default:
|
|
throw new ArgumentOutOfRangeException();
|
|
}
|
|
|
|
CloseAllPopup();
|
|
}
|
|
|
|
public void MoveNextStage()
|
|
{
|
|
DataManager.Inst.CurrentSaveStage++;
|
|
|
|
RestartCurrentStage();
|
|
}
|
|
|
|
public void MoveSelectStage(int stage)
|
|
{
|
|
DataManager.Inst.CurrentSaveStage = (SaveStage)stage;
|
|
|
|
RestartCurrentStage();
|
|
}
|
|
|
|
public void QuitGame()
|
|
{
|
|
#if UNITY_EDITOR
|
|
UnityEditor.EditorApplication.isPlaying = false;
|
|
#else
|
|
Application.Quit();
|
|
#endif
|
|
}
|
|
}
|
|
} |