60 lines
3.7 KiB
C#
60 lines
3.7 KiB
C#
using UnityEngine; // 유니티 기능을 불러올거에요 -> UnityEngine을
|
|
using UnityEngine.UI; // UI 기능을 불러올거에요 -> UnityEngine.UI를
|
|
using System.Collections; // 코루틴을 사용할거에요 -> System.Collections를
|
|
|
|
public class BossCounterFeedback : MonoBehaviour // 클래스를 선언할거에요 -> 피드백 시스템을
|
|
{
|
|
[SerializeField] private BossCounterSystem counterSystem; // 변수를 선언할거에요 -> 시스템 연결을
|
|
[SerializeField] private Text feedbackText; // 변수를 선언할거에요 -> 텍스트 UI를
|
|
[SerializeField] private float displayDuration = 3f; // 변수를 선언할거에요 -> 표시 시간을
|
|
|
|
private void OnEnable() // 함수를 실행할거에요 -> 활성화 시
|
|
{
|
|
if (counterSystem) // 조건이 맞으면 실행할거에요 -> 시스템이 연결되어 있다면
|
|
{
|
|
// ⭐ 매개변수 타입(string)이 일치하므로 이제 에러가 나지 않습니다.
|
|
counterSystem.OnCounterActivated.AddListener(ShowActivation); // 구독할거에요 -> 활성화 알림을
|
|
counterSystem.OnCounterDeactivated.AddListener(ShowDeactivation); // 구독할거에요 -> 비활성화 알림을
|
|
counterSystem.OnHabitChangeRewarded.AddListener(ShowReward); // 구독할거에요 -> 보상 알림을
|
|
}
|
|
}
|
|
|
|
private void OnDisable() // 함수를 실행할거에요 -> 비활성화 시
|
|
{
|
|
if (counterSystem) // 조건이 맞으면 실행할거에요 -> 시스템이 연결되어 있다면
|
|
{
|
|
counterSystem.OnCounterActivated.RemoveListener(ShowActivation); // 해지할거에요 -> 구독을
|
|
counterSystem.OnCounterDeactivated.RemoveListener(ShowDeactivation); // 해지할거에요 -> 구독을
|
|
counterSystem.OnHabitChangeRewarded.RemoveListener(ShowReward); // 해지할거에요 -> 구독을
|
|
}
|
|
}
|
|
|
|
// ⭐ [수정] string 매개변수 추가 (이벤트 시그니처 일치)
|
|
private void ShowActivation(string id) => ShowMsg($"⚠️ 패턴 감지: {id} 증가!"); // 실행할거에요 -> 메시지 출력을
|
|
private void ShowDeactivation(string id) => ShowMsg($"✅ 패턴 해소: {id} 감소"); // 실행할거에요 -> 메시지 출력을
|
|
private void ShowReward(string id) => ShowMsg($"🎉 습관 보상 획득! ({id})"); // 실행할거에요 -> 메시지 출력을
|
|
|
|
private void ShowMsg(string msg) // 함수를 선언할거에요 -> 텍스트 출력 로직을
|
|
{
|
|
if (feedbackText) // 조건이 맞으면 실행할거에요 -> 텍스트 컴포넌트가 있다면
|
|
{
|
|
feedbackText.text = msg; // 넣을거에요 -> 메시지 내용을
|
|
feedbackText.gameObject.SetActive(true); // 켤거에요 -> 텍스트 오브젝트를
|
|
StopAllCoroutines(); // 중단할거에요 -> 이전 코루틴을
|
|
StartCoroutine(HideRoutine()); // 시작할거에요 -> 숨기기 타이머를
|
|
}
|
|
Debug.Log($"[Feedback] {msg}"); // 로그를 찍을거에요 -> 콘솔 확인용으로
|
|
}
|
|
|
|
private IEnumerator HideRoutine() // 코루틴 함수를 정의할거에요 -> 숨기기 타이머를
|
|
{
|
|
yield return new WaitForSeconds(displayDuration); // 기다릴거에요 -> 설정된 시간만큼
|
|
if (feedbackText) feedbackText.gameObject.SetActive(false); // 끌거에요 -> 텍스트를
|
|
}
|
|
|
|
public void OnClickReset() // 함수를 선언할거에요 -> 리셋 버튼 기능을
|
|
{
|
|
if (BossCounterPersistence.Instance) // 조건이 맞으면 실행할거에요 -> 인스턴스가 존재하면
|
|
BossCounterPersistence.Instance.ResetAllData(); // 실행할거에요 -> 데이터 초기화를
|
|
}
|
|
} |