using System.Collections.Generic; using UnityEngine; using Platformer.Mechanics; using EerieVillage.MyUI; namespace EerieVillage.Progression { /// /// 레벨업 발화 시 일시정지 + UI 호출 + 카드 선택 결과 수령. /// PlayerProgression.OnLevelUp 구독. /// /// Phase 2-B 영역 (2026-05-08) — SkillSelectionUI 정식 통합. /// 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(); if (_player == null) { Debug.LogWarning("[LevelUpManager] PlayerController 영역 부재 — Start 시점 참조 X"); return; } _progression = _player.GetComponent(); if (_progression == null) { _progression = _player.gameObject.AddComponent(); } _progression.OnLevelUp += HandleLevelUp; if (_pool == null) _pool = GetComponent(); } void OnDestroy() { if (_progression != null) _progression.OnLevelUp -= HandleLevelUp; if (Instance == this) Instance = null; } void HandleLevelUp(int newLevel) { if (_isLevelUpActive) return; _isLevelUpActive = true; // 일시정지 + 입력 차단 Time.timeScale = 0f; if (_player != null) _player.controlEnabled = false; // 카드 3장 무작위 추출 List cards = _pool != null ? _pool.Draw3Random() : new List(); // Phase 2-B 영역 — SkillSelectionUI 정식 호출 if (_ui != null) { _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; } } }