64 lines
4.1 KiB
C#
64 lines
4.1 KiB
C#
using UnityEngine; // 유니티 기능을 불러올거에요 -> UnityEngine을
|
|
using System.Collections.Generic; // 딕셔너리를 사용할거에요 -> System.Collections.Generic을
|
|
using UnityEngine.Events; // 이벤트를 사용할거에요 -> UnityEngine.Events를
|
|
|
|
public class BossCounterSystem : MonoBehaviour // 클래스를 선언할거에요 -> 보스 카운터 시스템을
|
|
{
|
|
[Header("설정")] // 인스펙터 제목을 달거에요 -> 설정을
|
|
[SerializeField] private BossCounterConfig config; // 변수를 선언할거에요 -> 설정 파일 에셋을
|
|
[SerializeField] private bool usePersistence = true; // 변수를 선언할거에요 -> 저장 사용 여부를
|
|
|
|
private Dictionary<CounterType, int> _counters = new Dictionary<CounterType, int>(); // 변수를 선언할거에요 -> 내부 카운터 데이터를
|
|
private PatternSelector _selector; // 변수를 선언할거에요 -> 패턴 선택 헬퍼를
|
|
private BossCounterPersistence _persistence; // 변수를 선언할거에요 -> 저장소 헬퍼를
|
|
|
|
// ⭐ [핵심] string을 매개변수로 받는 이벤트로 통일 (Feedback 스크립트 에러 해결용)
|
|
public UnityEvent<CounterType, int> OnCounterUpdated; // 이벤트를 선언할거에요 -> 수치 변경 알림을
|
|
public UnityEvent<string> OnCounterActivated; // 이벤트를 선언할거에요 -> 활성화 알림을 (string)
|
|
public UnityEvent<string> OnCounterDeactivated; // 이벤트를 선언할거에요 -> 비활성화 알림을 (string)
|
|
public UnityEvent<string> OnHabitChangeRewarded; // 이벤트를 선언할거에요 -> 보상 알림을 (string)
|
|
|
|
private void Awake() // 함수를 실행할거에요 -> 초기화 Awake를
|
|
{
|
|
_selector = new PatternSelector(config); // 생성할거에요 -> 패턴 선택기를
|
|
_persistence = GetComponent<BossCounterPersistence>(); // 가져올거에요 -> 저장소 컴포넌트를
|
|
if (!_persistence) _persistence = gameObject.AddComponent<BossCounterPersistence>(); // 없으면 추가할거에요 -> 저장소를
|
|
|
|
foreach (CounterType t in System.Enum.GetValues(typeof(CounterType))) _counters[t] = 0; // 초기화할거에요 -> 모든 카운터를 0으로
|
|
}
|
|
|
|
private void Start() // 함수를 실행할거에요 -> 시작 Start를
|
|
{
|
|
if (usePersistence && _persistence) _persistence.LoadData(_counters); // 불러올거에요 -> 저장된 데이터를
|
|
}
|
|
|
|
public void InitializeBattle() { } // 함수를 비워둘거에요 -> 외부 호출 호환성을 위해
|
|
|
|
public void RegisterPlayerAction(CounterType type) // 함수를 선언할거에요 -> 플레이어 행동 기록을
|
|
{
|
|
if (!_counters.ContainsKey(type)) _counters[type] = 0; // 없으면 만들거에요 -> 키를
|
|
_counters[type]++; // 증가시킬거에요 -> 카운트 값을
|
|
|
|
OnCounterUpdated?.Invoke(type, _counters[type]); // 알릴거에요 -> 수치 변경 이벤트를
|
|
OnCounterActivated?.Invoke(type.ToString()); // 알릴거에요 -> 활성화 이벤트를 문자열로 변환해서
|
|
}
|
|
|
|
public string SelectBossPattern() // 함수를 선언할거에요 -> 패턴 선택을
|
|
{
|
|
string pattern = _selector.SelectPattern(_counters); // 선택할거에요 -> 헬퍼를 통해 패턴을
|
|
|
|
var keys = new List<CounterType>(_counters.Keys); // 복사할거에요 -> 키 목록을
|
|
foreach (var k in keys) if (_counters[k] > 0) _counters[k]--; // 줄일거에요 -> 쿨다운을 위해 값을
|
|
|
|
if (usePersistence && _persistence) _persistence.SaveData(_counters); // 저장할거에요 -> 갱신된 데이터를
|
|
return pattern; // 반환할거에요 -> 선택된 패턴 이름을
|
|
}
|
|
|
|
public Dictionary<CounterType, int> GetActiveCounters() => new Dictionary<CounterType, int>(_counters); // 반환할거에요 -> 데이터 복사본을
|
|
|
|
// ⭐ [복구] 보상 여부 확인 함수
|
|
public bool IsHabitChangeRewarded() // 함수를 선언할거에요 -> 보상 획득 여부 확인을
|
|
{
|
|
return false; // 임시 반환할거에요 -> 로직 구현 전까지 거짓(false)을
|
|
}
|
|
} |