using UnityEngine;
using UnityEngine.SceneManagement;
using Platformer.Mechanics;
namespace Platformer.UI
{
///
/// Health.OnDeathEvent 수신 시 부활/재시작 팝업 표시.
/// PD 지시 2026-05-07:
/// - 예 → 제자리 부활 (Health.Resurrect, 부활 직후 2초 무적)
/// - 아니오 → 씬 재시작 (SceneManager.LoadScene)
/// 임시 OnGUI 영역 — 향후 uGUI Canvas 영역으로 미관 정정 별건.
///
[RequireComponent(typeof(Health))]
public class ResurrectPromptUI : MonoBehaviour
{
Health health;
bool showPrompt;
void Awake()
{
health = GetComponent();
if (health != null)
{
health.OnDeathEvent += OnDeath;
health.OnResurrectEvent += OnResurrect;
}
}
void OnDestroy()
{
if (health != null)
{
health.OnDeathEvent -= OnDeath;
health.OnResurrectEvent -= OnResurrect;
}
}
void OnDeath()
{
showPrompt = true;
Time.timeScale = 0f;
}
void OnResurrect()
{
showPrompt = false;
Time.timeScale = 1f;
}
void OnGUI()
{
if (!showPrompt) return;
float w = 360f, h = 200f;
float x = (Screen.width - w) * 0.5f;
float y = (Screen.height - h) * 0.5f;
GUI.Box(new Rect(x, y, w, h), "사망 — 부활하시겠습니까?");
if (GUI.Button(new Rect(x + 30f, y + 110f, 130f, 60f), "예 (제자리 부활)"))
{
if (health != null)
{
health.canResurrect = true;
health.Resurrect();
}
}
if (GUI.Button(new Rect(x + 200f, y + 110f, 130f, 60f), "아니오 (재시작)"))
{
Time.timeScale = 1f;
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
}
}