118 lines
3.5 KiB
C#
118 lines
3.5 KiB
C#
|
|
using UnityEngine;
|
|||
|
|
|
|||
|
|
public class ObsessionSystem : MonoBehaviour
|
|||
|
|
{
|
|||
|
|
public static ObsessionSystem instance;
|
|||
|
|
|
|||
|
|
[SerializeField] private int currentXP = 0; // ★ 영구 XP (저장되는 진짜 진행도)
|
|||
|
|
[SerializeField] private int currentLevel = 1;
|
|||
|
|
[SerializeField] private int[] xpRequirements = { 100, 300, 500, 800, 1200 };
|
|||
|
|
|
|||
|
|
// ★ ★ ★ NEW: 이번 런에서 쌓은 임시 XP ★ ★ ★
|
|||
|
|
[SerializeField] private int currentRunXP = 0; // 이 값은 게임 껐다 키면 사라져요!
|
|||
|
|
|
|||
|
|
private void Awake()
|
|||
|
|
{
|
|||
|
|
if (instance == null)
|
|||
|
|
{
|
|||
|
|
instance = this;
|
|||
|
|
DontDestroyOnLoad(gameObject);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
Destroy(gameObject);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void Start()
|
|||
|
|
{
|
|||
|
|
LoadData();
|
|||
|
|
Debug.Log($"[집착 시스템] 시작! 현재 레벨: {currentLevel}, XP: {currentXP}");
|
|||
|
|
|
|||
|
|
// ★ ★ ★ NEW: 새 런 시작할 때 임시 XP는 0으로 초기화 ★ ★ ★
|
|||
|
|
currentRunXP = 0;
|
|||
|
|
Debug.Log($"[새 런 시작] 이번 런에 쌓을 임시 XP: 0");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ★ ★ ★ NEW: 플레이 중 실시간으로 임시 XP 추가 ★ ★ ★
|
|||
|
|
public void AddRunXP(int amount)
|
|||
|
|
{
|
|||
|
|
currentRunXP += amount;
|
|||
|
|
Debug.Log($"[런 XP 획득] +{amount}XP (이번 런 총: {currentRunXP})");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ★ ★ ★ NEW: 사망 시 임시 XP를 영구 XP로 변환 ★ ★ ★
|
|||
|
|
public void OnDeathConvertXP()
|
|||
|
|
{
|
|||
|
|
Debug.Log($"[사망] 이번 런 성과: {currentRunXP}XP를 영구 XP로 전환!");
|
|||
|
|
|
|||
|
|
// 임시 XP를 영구 XP에 추가
|
|||
|
|
AddXP(currentRunXP);
|
|||
|
|
|
|||
|
|
// 임시 XP는 초기화 (다음 런을 위해)
|
|||
|
|
currentRunXP = 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 기존 AddXP 함수 (이제는 사망할 때만 호출될 거예요)
|
|||
|
|
public void AddXP(int amount)
|
|||
|
|
{
|
|||
|
|
currentXP += amount;
|
|||
|
|
Debug.Log($"[영구 XP 획득] +{amount}XP (현재: {currentXP})");
|
|||
|
|
CheckLevelUp();
|
|||
|
|
SaveData();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void CheckLevelUp()
|
|||
|
|
{
|
|||
|
|
if (currentLevel - 1 < xpRequirements.Length)
|
|||
|
|
{
|
|||
|
|
int requiredXP = xpRequirements[currentLevel - 1];
|
|||
|
|
if (currentXP >= requiredXP)
|
|||
|
|
{
|
|||
|
|
currentLevel++;
|
|||
|
|
Debug.Log($"🎉 [레벨업!] 레벨 {currentLevel - 1} → {currentLevel}");
|
|||
|
|
UnlockRewards(currentLevel);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void UnlockRewards(int level)
|
|||
|
|
{
|
|||
|
|
// 보상 코드는 기존과 동일
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void SaveData()
|
|||
|
|
{
|
|||
|
|
PlayerPrefs.SetInt("ObsessionLevel", currentLevel);
|
|||
|
|
PlayerPrefs.SetInt("ObsessionXP", currentXP);
|
|||
|
|
PlayerPrefs.Save();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void LoadData()
|
|||
|
|
{
|
|||
|
|
currentLevel = PlayerPrefs.GetInt("ObsessionLevel", 1);
|
|||
|
|
currentXP = PlayerPrefs.GetInt("ObsessionXP", 0);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|||
|
|
// 🧪 테스트용: 현재 상태를 읽는 함수들
|
|||
|
|
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|||
|
|
|
|||
|
|
// 현재 런 XP 확인
|
|||
|
|
public int GetCurrentRunXP()
|
|||
|
|
{
|
|||
|
|
return currentRunXP;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 현재 영구 XP 확인
|
|||
|
|
public int GetCurrentXP()
|
|||
|
|
{
|
|||
|
|
return currentXP;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 현재 레벨 확인
|
|||
|
|
public int GetCurrentLevel()
|
|||
|
|
{
|
|||
|
|
return currentLevel;
|
|||
|
|
}
|
|||
|
|
}
|