106 lines
3.7 KiB
C#
106 lines
3.7 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using Platformer.Mechanics;
|
|
using EerieVillage.MyUI;
|
|
|
|
namespace EerieVillage.Progression
|
|
{
|
|
/// <summary>
|
|
/// 레벨업 발화 시 일시정지 + UI 호출 + 카드 선택 결과 수령.
|
|
/// PlayerProgression.OnLevelUp 구독.
|
|
///
|
|
/// Phase 2-B 영역 (2026-05-08) — SkillSelectionUI 정식 통합.
|
|
/// </summary>
|
|
public class LevelUpManager : MonoBehaviour
|
|
{
|
|
public static LevelUpManager Instance { get; private set; }
|
|
|
|
[SerializeField] SkillCardPlaceholderPool _pool;
|
|
[SerializeField] SkillSelectionUI _ui;
|
|
|
|
PlayerController _player;
|
|
PlayerProgression _progression;
|
|
bool _isLevelUpActive = false;
|
|
|
|
void Awake()
|
|
{
|
|
if (Instance != null && Instance != this)
|
|
{
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
Instance = this;
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
_player = Object.FindFirstObjectByType<PlayerController>();
|
|
if (_player == null)
|
|
{
|
|
Debug.LogWarning("[LevelUpManager] PlayerController 영역 부재 — Start 시점 참조 X");
|
|
return;
|
|
}
|
|
|
|
_progression = _player.GetComponent<PlayerProgression>();
|
|
if (_progression == null)
|
|
{
|
|
_progression = _player.gameObject.AddComponent<PlayerProgression>();
|
|
}
|
|
_progression.OnLevelUp += HandleLevelUp;
|
|
|
|
if (_pool == null) _pool = GetComponent<SkillCardPlaceholderPool>();
|
|
}
|
|
|
|
void OnDestroy()
|
|
{
|
|
if (_progression != null) _progression.OnLevelUp -= HandleLevelUp;
|
|
if (Instance == this) Instance = null;
|
|
}
|
|
|
|
void HandleLevelUp(int newLevel)
|
|
{
|
|
Debug.Log($"[LevelUpManager] HandleLevelUp 호출 Lv.{newLevel} _ui={(_ui == null ? "NULL" : _ui.name)} _pool={(_pool == null ? "NULL" : _pool.name)}");
|
|
if (_isLevelUpActive) return;
|
|
_isLevelUpActive = true;
|
|
|
|
// 일시정지 + 입력 차단
|
|
Time.timeScale = 0f;
|
|
if (_player != null) _player.controlEnabled = false;
|
|
|
|
// 카드 3장 무작위 추출
|
|
List<SkillCardPlaceholder> cards = _pool != null
|
|
? _pool.Draw3Random()
|
|
: new List<SkillCardPlaceholder>();
|
|
Debug.Log($"[LevelUpManager] cards.Count={cards.Count}");
|
|
|
|
// Phase 2-B 영역 — SkillSelectionUI 정식 호출
|
|
if (_ui != null)
|
|
{
|
|
Debug.Log($"[LevelUpManager] _ui.Show 호출 → SkillSelectionCanvas 활성 의도");
|
|
_ui.Show(cards, newLevel, HandleCardConfirmed);
|
|
}
|
|
else
|
|
{
|
|
// UI 영역 부재 fallback (placeholder asset 5장 미등록 영역 등)
|
|
Debug.LogWarning($"[LevelUpManager] SkillSelectionUI 부재 — Lv.{newLevel} 카드 {cards.Count}장 영역 자동 확정");
|
|
HandleCardConfirmed(cards.Count > 0 ? cards[0] : null);
|
|
}
|
|
}
|
|
|
|
void HandleCardConfirmed(SkillCardPlaceholder selected)
|
|
{
|
|
// UI 닫기
|
|
if (_ui != null) _ui.Hide();
|
|
|
|
// 차기 BT12-Dev 영역 = PlayerSkillInventory.AddSkillByCardId(selected.id)
|
|
// BT12-MVP-A 영역 = UI 닫기·게임 재개만
|
|
Debug.Log($"[LevelUpManager] 카드 확정 — {(selected != null ? selected.displayName : "NONE")} (효과 적용 X·BT12-Dev 본격 영역)");
|
|
|
|
// 일시정지 해제 + 입력 복원
|
|
Time.timeScale = 1f;
|
|
if (_player != null) _player.controlEnabled = true;
|
|
_isLevelUpActive = false;
|
|
}
|
|
}
|
|
}
|