2026-01-29 06:58:38 +00:00
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using TMPro;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
|
|
public class PlayerLevelSystem : MonoBehaviour
|
|
|
|
|
|
{
|
2026-01-29 16:11:10 +00:00
|
|
|
|
[Header("--- 참조 ---")]
|
|
|
|
|
|
[SerializeField] private Stats stats;
|
|
|
|
|
|
[SerializeField] private PlayerHealth pHealth;
|
|
|
|
|
|
|
|
|
|
|
|
[Header("레벨 설정")]
|
2026-01-29 06:58:38 +00:00
|
|
|
|
public int level = 1;
|
|
|
|
|
|
public int currentExp = 0;
|
|
|
|
|
|
[SerializeField] private int[] expTable;
|
|
|
|
|
|
|
|
|
|
|
|
[Header("UI")]
|
|
|
|
|
|
[SerializeField] private Image expFillImage;
|
|
|
|
|
|
[SerializeField] private TextMeshProUGUI expText;
|
2026-01-29 16:11:10 +00:00
|
|
|
|
[SerializeField] private TextMeshProUGUI levelText;
|
2026-01-29 06:58:38 +00:00
|
|
|
|
|
|
|
|
|
|
public static System.Action OnLevelUp;
|
|
|
|
|
|
|
|
|
|
|
|
private int RequiredExp
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
int index = level - 1;
|
2026-01-29 16:11:10 +00:00
|
|
|
|
if (index >= expTable.Length) return expTable[expTable.Length - 1];
|
2026-01-29 06:58:38 +00:00
|
|
|
|
return expTable[index];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnEnable()
|
|
|
|
|
|
{
|
|
|
|
|
|
MonsterClass.OnMonsterKilled += GainExp;
|
|
|
|
|
|
UpdateExpUI();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnDisable()
|
|
|
|
|
|
{
|
|
|
|
|
|
MonsterClass.OnMonsterKilled -= GainExp;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GainExp(int amount)
|
|
|
|
|
|
{
|
|
|
|
|
|
currentExp += amount;
|
|
|
|
|
|
while (currentExp >= RequiredExp)
|
|
|
|
|
|
{
|
|
|
|
|
|
currentExp -= RequiredExp;
|
|
|
|
|
|
LevelUp();
|
|
|
|
|
|
}
|
|
|
|
|
|
UpdateExpUI();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LevelUp()
|
|
|
|
|
|
{
|
2026-01-29 16:11:10 +00:00
|
|
|
|
if (level >= expTable.Length + 1) { currentExp = 0; return; }
|
|
|
|
|
|
|
|
|
|
|
|
level++;
|
|
|
|
|
|
Debug.Log($"🎉 [LevelSystem] 레벨 업! 현재 레벨: {level}");
|
|
|
|
|
|
|
|
|
|
|
|
// 1. 기초 스탯 먼저 상승 (체력 +1000, 힘 +100 - 유저님 설정값)
|
|
|
|
|
|
if (stats != null) stats.AddBaseLevelUpStats(1000f, 100f);
|
|
|
|
|
|
|
|
|
|
|
|
// 2. ⭐ [핵심] 늘어난 스탯으로 피 채우고 UI 즉시 갱신 함수 호출
|
|
|
|
|
|
if (pHealth != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
pHealth.RefreshHealthUI();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2026-01-29 06:58:38 +00:00
|
|
|
|
{
|
2026-01-29 16:11:10 +00:00
|
|
|
|
Debug.LogError("[LevelSystem] pHealth 참조가 비어있습니다! 인스펙터에 PlayerHealth를 드래그해서 넣어주세요.");
|
2026-01-29 06:58:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-29 16:11:10 +00:00
|
|
|
|
// 3. 1.5초 대기 후 카드 선택 UI 팝업
|
|
|
|
|
|
StartCoroutine(DelayedCardPopup());
|
|
|
|
|
|
}
|
2026-01-29 06:58:38 +00:00
|
|
|
|
|
2026-01-29 16:11:10 +00:00
|
|
|
|
private IEnumerator DelayedCardPopup()
|
|
|
|
|
|
{
|
|
|
|
|
|
yield return new WaitForSeconds(1.5f);
|
|
|
|
|
|
Debug.Log("1.5초 경과: 카드 UI 팝업 실행");
|
|
|
|
|
|
OnLevelUp?.Invoke();
|
2026-01-29 06:58:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UpdateExpUI()
|
|
|
|
|
|
{
|
|
|
|
|
|
float fill = (float)currentExp / RequiredExp;
|
2026-01-29 16:11:10 +00:00
|
|
|
|
if (expFillImage != null) expFillImage.fillAmount = fill;
|
|
|
|
|
|
if (expText != null) expText.text = $"{currentExp} / {RequiredExp}";
|
|
|
|
|
|
if (levelText != null) levelText.text = $"Lv. {level}";
|
2026-01-29 06:58:38 +00:00
|
|
|
|
}
|
2026-01-29 16:11:10 +00:00
|
|
|
|
}
|