using System.Collections.Generic; using UnityEngine; /// /// 런 간 영구 저장되는 보스 카운터 잠금 해제 데이터. /// "보스가 플레이어를 기억한다"는 서사를 담당합니다. /// /// 핵심 규칙: /// - 잠금 해제는 영구 (런이 끝나도 유지) /// - 발동은 조건부 (해당 런에서 플레이어가 습관을 보여야만 활성화) /// - 잠금 해제된 카운터는 임계치가 약간 낮아짐 (보스가 "이미 알고 있으니 더 빨리 눈치챔") /// [System.Serializable] public class BossCounterSaveData { public bool dodgeCounterUnlocked = false; public bool aimCounterUnlocked = false; public bool pierceCounterUnlocked = false; /// 각 카운터가 발동된 총 횟수 (연출/난이도 스케일링에 활용 가능) public int dodgeCounterActivations = 0; public int aimCounterActivations = 0; public int pierceCounterActivations = 0; } /// /// 보스 카운터 영구 데이터를 관리합니다. /// PlayerPrefs 기반으로 런 간 저장/로드합니다. /// public class BossCounterPersistence : MonoBehaviour { public static BossCounterPersistence Instance { get; private set; } private const string SAVE_KEY = "BossCounterData"; public BossCounterSaveData Data { get; private set; } private void Awake() { if (Instance != null && Instance != this) { Destroy(gameObject); return; } Instance = this; DontDestroyOnLoad(gameObject); Load(); } // ═══════════════════════════════════════════ // 잠금 해제 // ═══════════════════════════════════════════ /// 특정 카운터 타입을 영구 잠금 해제 public void UnlockCounter(CounterType type) { switch (type) { case CounterType.Dodge: if (!Data.dodgeCounterUnlocked) { Data.dodgeCounterUnlocked = true; Debug.Log("[BossCounter] 회피 카운터 영구 잠금 해제!"); } break; case CounterType.Aim: if (!Data.aimCounterUnlocked) { Data.aimCounterUnlocked = true; Debug.Log("[BossCounter] 조준 카운터 영구 잠금 해제!"); } break; case CounterType.Pierce: if (!Data.pierceCounterUnlocked) { Data.pierceCounterUnlocked = true; Debug.Log("[BossCounter] 관통 카운터 영구 잠금 해제!"); } break; } Save(); } /// 카운터가 잠금 해제되어 있는지 확인 public bool IsUnlocked(CounterType type) { return type switch { CounterType.Dodge => Data.dodgeCounterUnlocked, CounterType.Aim => Data.aimCounterUnlocked, CounterType.Pierce => Data.pierceCounterUnlocked, _ => false }; } /// 카운터 발동 횟수 기록 public void RecordActivation(CounterType type) { switch (type) { case CounterType.Dodge: Data.dodgeCounterActivations++; break; case CounterType.Aim: Data.aimCounterActivations++; break; case CounterType.Pierce: Data.pierceCounterActivations++; break; } Save(); } // ═══════════════════════════════════════════ // 저장 / 로드 / 리셋 // ═══════════════════════════════════════════ public void Save() { string json = JsonUtility.ToJson(Data); PlayerPrefs.SetString(SAVE_KEY, json); PlayerPrefs.Save(); } public void Load() { if (PlayerPrefs.HasKey(SAVE_KEY)) { string json = PlayerPrefs.GetString(SAVE_KEY); Data = JsonUtility.FromJson(json); } else { Data = new BossCounterSaveData(); } } /// 모든 영구 데이터 초기화 (디버그/뉴게임+) public void ResetAllData() { Data = new BossCounterSaveData(); PlayerPrefs.DeleteKey(SAVE_KEY); Debug.Log("[BossCounter] 모든 보스 기억 데이터 초기화됨"); } }