using UnityEngine;
using Colosseum.Abnormalities;
namespace Colosseum.UI
{
///
/// 이상 상태 시스템 테스트 스크립트
/// Q 키: 버프 적용, E 키: 디버프 적용
/// 로그를 통해 OnEffect 이벤트 호출 및 이상 상태 적용 과정을 추적합니다.
///
public class AbnormalitySystemTest : MonoBehaviour
{
private AbnormalityManager abnormalityManager;
private AbnormalityData testBuff;
private AbnormalityData testDebuff;
private float testTimer;
void Start()
{
// 플레이어에서 AbnormalityManager 찾기
abnormalityManager = GetComponent();
if (abnormalityManager == null)
{
Debug.LogError("[AbnormalitySystemTest] AbnormalityManager not found on player!");
return;
}
// 테스트용 이상 상태 데이터 생성 (에셋 생성)
testBuff = ScriptableObject.CreateInstance();
testBuff.abnormalityName = "Test Buff";
testBuff.duration = 5f;
testBuff.isDebuff = false;
testDebuff = ScriptableObject.CreateInstance();
testDebuff.abnormalityName = "Test Debuff";
testDebuff.duration = 5f;
testDebuff.isDebuff = true;
// 이벤트 구독
abnormalityManager.OnAbnormalityAdded += OnAbnormalityAdded;
abnormalityManager.OnAbnormalityRemoved += OnAbnormalityRemoved;
Debug.Log("=== Abnormality System Test Started ===");
Debug.Log("Press Q to apply buff, Press E to apply debuff");
Debug.Log($"Initial Active Abnormalities Count: {abnormalityManager.ActiveAbnormalities.Count}");
}
void Update()
{
testTimer += Time.deltaTime;
// Q 키로 버프 적용 (3초마다 1회만)
if (Input.GetKeyDown(KeyCode.Q) && testTimer >= 3f)
{
testTimer = 0f;
ApplyTestBuff();
}
// E 키로 디버프 적용 (3초마다 1회만)
if (Input.GetKeyDown(KeyCode.E) && testTimer >= 3f)
{
testTimer = 0f;
ApplyTestDebuff();
}
}
private void ApplyTestBuff()
{
if (testBuff == null || abnormalityManager == null)
{
Debug.LogWarning("[AbnormalitySystemTest] Cannot apply buff - data or manager is null");
return;
}
Debug.Log($"[AbnormalitySystemTest] >>> Applying BUFF: {testBuff.abnormalityName} to {gameObject.name}");
abnormalityManager.ApplyAbnormality(testBuff, gameObject);
}
private void ApplyTestDebuff()
{
if (testDebuff == null || abnormalityManager == null)
{
Debug.LogWarning("[AbnormalitySystemTest] Cannot apply debuff - data or manager is null");
return;
}
Debug.Log($"[AbnormalitySystemTest] >>> Applying DEBUFF: {testDebuff.abnormalityName} to {gameObject.name}");
abnormalityManager.ApplyAbnormality(testDebuff, gameObject);
}
private void OnAbnormalityAdded(ActiveAbnormality abnormality)
{
Debug.Log($"[AbnormalitySystemTest] <<< ABNORMALITY ADDED: {abnormality.Data.abnormalityName} | isDebuff: {abnormality.Data.isDebuff} | Duration: {abnormality.Data.duration}s | Remaining: {abnormality.RemainingDuration:F1}s");
}
private void OnAbnormalityRemoved(ActiveAbnormality abnormality)
{
Debug.Log($"[AbnormalitySystemTest] <<< ABNORMALITY REMOVED: {abnormality.Data.abnormalityName}");
}
void OnDestroy()
{
// 이벤트 구독 해제
if (abnormalityManager != null)
{
abnormalityManager.OnAbnormalityAdded -= OnAbnormalityAdded;
abnormalityManager.OnAbnormalityRemoved -= OnAbnormalityRemoved;
}
// 정리
if (testBuff != null) Destroy(testBuff);
if (testDebuff != null) Destroy(testDebuff);
}
}
}