Projext/Assets/02_Scripts/Enemy/BossAI/BossCounterPersistence.cs
hydrozen e989d20668 카툰 쉐이더 추가 + 중복 스크립트 수정 + 전체 업데이트
- ToonPostProcess.shader: 횃불 고딕 스타일 후처리 쉐이더 (Built-in RP)
- ToonCameraEffect.cs: 카메라 자동 부착 후처리 스크립트
- 중복 UI 스크립트 제거 (MenuIntroController, ToggleCustom)
- 씬, 프리팹, 애니메이션 등 전체 업데이트

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-22 12:31:16 +09:00

63 lines
3.9 KiB
C#

using UnityEngine; // 유니티 기능을 불러올거에요 -> UnityEngine을
using System.Collections.Generic; // 딕셔너리를 사용할거에요 -> System.Collections.Generic을
public class BossCounterPersistence : MonoBehaviour // 클래스를 선언할거에요 -> 데이터 저장을 담당하는 BossCounterPersistence를
{
public static BossCounterPersistence Instance { get; private set; } // 프로퍼티를 선언할거에요 -> 싱글톤 인스턴스를
// ⭐ [복구] 외부(DebugPanel 등)에서 참조하던 데이터 저장소
public Dictionary<CounterType, int> Data { get; private set; } = new Dictionary<CounterType, int>(); // 프로퍼티를 선언할거에요 -> 카운터 데이터를 담을 딕셔너리를
private void Awake() // 함수를 실행할거에요 -> 초기화 Awake를
{
if (Instance == null) // 조건이 맞으면 실행할거에요 -> 아직 인스턴스가 없으면
{
Instance = this; // 설정할거에요 -> 나를 유일한 인스턴스로
}
else if (Instance != this) // 조건이 맞으면 실행할거에요 -> 이미 다른 인스턴스가 있으면
{
Debug.Log("[BossPersistence] 중복 감지 → 컴포넌트만 제거 (게임오브젝트 보존)"); // 로그를 찍을거에요
Destroy(this); // 파괴할거에요 -> 컴포넌트만! (gameObject가 아닌 this = BossCounterPersistence 컴포넌트만 제거)
return; // 중단할거에요 -> 이후 로직 실행 방지
}
}
public void SaveData(Dictionary<CounterType, int> counters) // 함수를 선언할거에요 -> 저장을 수행하는 SaveData를
{
Data = counters; // 갱신할거에요 -> 내부 데이터 프로퍼티를
foreach (var pair in counters) // 반복할거에요 -> 모든 카운터를
{
PlayerPrefs.SetInt($"BossCounter_{pair.Key}", pair.Value); // 저장할거에요 -> PlayerPrefs에 키와 값을
}
PlayerPrefs.Save(); // 확정할거에요 -> 저장을
Debug.Log("💾 [BossPersistence] 데이터 저장됨"); // 로그를 찍을거에요 -> 저장 완료 메시지를
}
public void LoadData(Dictionary<CounterType, int> counters) // 함수를 선언할거에요 -> 불러오기를 수행하는 LoadData를
{
foreach (CounterType type in System.Enum.GetValues(typeof(CounterType))) // 반복할거에요 -> 모든 타입을 돌면서
{
string key = $"BossCounter_{type}"; // 키를 만들거에요 -> 저장된 키 이름을
int val = PlayerPrefs.GetInt(key, 0); // 불러올거에요 -> 저장된 값을 (없으면 0)
if (counters.ContainsKey(type)) counters[type] = val; // 조건이 맞으면 갱신할거에요 -> 딕셔너리 값을
else counters.Add(type, val); // 아니면 추가할거에요 -> 딕셔너리에 값을
}
Data = counters; // 동기화할거에요 -> 내부 데이터 프로퍼티를
Debug.Log("📂 [BossPersistence] 데이터 로드됨"); // 로그를 찍을거에요 -> 로드 완료 메시지를
}
// ⭐ [복구] 외부에서 호출하는 데이터 초기화 함수
public void ResetAllData() // 함수를 선언할거에요 -> 모든 데이터를 삭제하는 ResetAllData를
{
PlayerPrefs.DeleteAll(); // 삭제할거에요 -> 저장된 모든 프리팹 데이터를
Data.Clear(); // 비울거에요 -> 메모리 상의 데이터를
Debug.Log("🗑️ [BossPersistence] 초기화 완료"); // 로그를 찍을거에요 -> 초기화 완료 메시지를
}
// ⭐ [복구] 해금 여부 확인 함수
public bool IsUnlocked(CounterType type) // 함수를 선언할거에요 -> 해금 여부를 반환하는 IsUnlocked를
{
return Data.ContainsKey(type) && Data[type] > 0; // 반환할거에요 -> 데이터가 있고 0보다 큰지 여부를
}
}