2026-04-23 14:50:20 +00:00
|
|
|
using System.Linq;
|
2026-04-23 14:47:51 +00:00
|
|
|
using NUnit.Framework;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// EerieVillage BT5-Dev 2단계 — Player 근거리 공격 체계 EditMode 테스트.
|
|
|
|
|
/// Prefab 자산의 컴포넌트 구성이 기획 04 §5-1 (근거리 공격 1종) 을 충족하는지 검증.
|
|
|
|
|
/// Play 모드 실행 불요 — prefab YAML 직렬화 상태를 직접 검증하여 회귀 방지.
|
2026-04-23 14:50:20 +00:00
|
|
|
///
|
|
|
|
|
/// 2026-04-23 개정: Platformer.* 네임스페이스 직접 참조 제거 (Scripts/ 하위에 asmdef 부재로
|
|
|
|
|
/// 테스트 어셈블리가 Assembly-CSharp 를 참조 불가한 구조 — reflection 기반으로 전환).
|
2026-04-23 14:47:51 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public class PlayerAttackTests
|
|
|
|
|
{
|
|
|
|
|
const string PlayerPrefabPath = "Assets/Prefabs/Player.prefab";
|
|
|
|
|
const string EnemyPrefabPath = "Assets/Prefabs/Enemy.prefab";
|
|
|
|
|
|
2026-04-23 14:50:20 +00:00
|
|
|
// Platformer.* 는 Assembly-CSharp 에 속함. 테스트 어셈블리에서 직접 타입 참조 불가하므로
|
|
|
|
|
// GetComponents<Component>() + GetType().FullName 매칭으로 검증.
|
|
|
|
|
const string AttackHitboxType = "Platformer.Mechanics.AttackHitbox";
|
|
|
|
|
const string HealthType = "Platformer.Mechanics.Health";
|
|
|
|
|
const string PlayerControllerType = "Platformer.Mechanics.PlayerController";
|
|
|
|
|
const string EnemyControllerType = "Platformer.Mechanics.EnemyController";
|
|
|
|
|
|
|
|
|
|
static Component FindComponentByFullName(GameObject go, string fullName)
|
|
|
|
|
{
|
|
|
|
|
if (go == null) return null;
|
|
|
|
|
return go.GetComponents<Component>()
|
|
|
|
|
.FirstOrDefault(c => c != null && c.GetType().FullName == fullName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static object GetFieldOrProperty(object obj, string memberName)
|
|
|
|
|
{
|
|
|
|
|
if (obj == null) return null;
|
|
|
|
|
var t = obj.GetType();
|
|
|
|
|
var field = t.GetField(memberName,
|
|
|
|
|
System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
|
|
|
|
|
if (field != null) return field.GetValue(obj);
|
|
|
|
|
var prop = t.GetProperty(memberName,
|
|
|
|
|
System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
|
|
|
|
|
return prop?.GetValue(obj);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-23 14:47:51 +00:00
|
|
|
[Test]
|
|
|
|
|
public void Player_Prefab_Has_AttackHitbox_Component()
|
|
|
|
|
{
|
|
|
|
|
var prefab = AssetDatabase.LoadAssetAtPath<GameObject>(PlayerPrefabPath);
|
|
|
|
|
Assert.IsNotNull(prefab, $"Player.prefab not found at {PlayerPrefabPath}");
|
|
|
|
|
|
2026-04-23 14:50:20 +00:00
|
|
|
var hitbox = FindComponentByFullName(prefab, AttackHitboxType);
|
2026-04-23 14:47:51 +00:00
|
|
|
Assert.IsNotNull(hitbox,
|
|
|
|
|
"Player.prefab에 AttackHitbox 컴포넌트가 누락. " +
|
|
|
|
|
"BT5-Dev 2단계 재위임 집행분 (2026-04-23) 이 prefab YAML 에 반영되어야 함.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Player_Prefab_Has_Health_Component()
|
|
|
|
|
{
|
|
|
|
|
var prefab = AssetDatabase.LoadAssetAtPath<GameObject>(PlayerPrefabPath);
|
|
|
|
|
Assert.IsNotNull(prefab, $"Player.prefab not found at {PlayerPrefabPath}");
|
|
|
|
|
|
2026-04-23 14:50:20 +00:00
|
|
|
var health = FindComponentByFullName(prefab, HealthType);
|
2026-04-23 14:47:51 +00:00
|
|
|
Assert.IsNotNull(health, "Player.prefab 에 Health 컴포넌트 누락 (템플릿 기본).");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Player_Prefab_Has_PlayerController_Component()
|
|
|
|
|
{
|
|
|
|
|
var prefab = AssetDatabase.LoadAssetAtPath<GameObject>(PlayerPrefabPath);
|
|
|
|
|
Assert.IsNotNull(prefab);
|
|
|
|
|
|
2026-04-23 14:50:20 +00:00
|
|
|
var controller = FindComponentByFullName(prefab, PlayerControllerType);
|
2026-04-23 14:47:51 +00:00
|
|
|
Assert.IsNotNull(controller, "Player.prefab 에 PlayerController 컴포넌트 누락.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void AttackHitbox_Default_Damage_Is_One()
|
|
|
|
|
{
|
|
|
|
|
var prefab = AssetDatabase.LoadAssetAtPath<GameObject>(PlayerPrefabPath);
|
2026-04-23 14:50:20 +00:00
|
|
|
var hitbox = FindComponentByFullName(prefab, AttackHitboxType);
|
2026-04-23 14:47:51 +00:00
|
|
|
Assert.IsNotNull(hitbox);
|
|
|
|
|
|
2026-04-23 14:50:20 +00:00
|
|
|
var damage = GetFieldOrProperty(hitbox, "damage");
|
|
|
|
|
Assert.IsNotNull(damage, "AttackHitbox.damage 필드/프로퍼티 접근 불가");
|
|
|
|
|
Assert.AreEqual(1, System.Convert.ToInt32(damage),
|
2026-04-23 14:47:51 +00:00
|
|
|
"기본 대미지 1 (기획 04 §5-1, Phase 3-B 튠 전 파일럿 값).");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void AttackHitbox_Active_Duration_Is_Positive()
|
|
|
|
|
{
|
|
|
|
|
var prefab = AssetDatabase.LoadAssetAtPath<GameObject>(PlayerPrefabPath);
|
2026-04-23 14:50:20 +00:00
|
|
|
var hitbox = FindComponentByFullName(prefab, AttackHitboxType);
|
2026-04-23 14:47:51 +00:00
|
|
|
Assert.IsNotNull(hitbox);
|
|
|
|
|
|
2026-04-23 14:50:20 +00:00
|
|
|
var duration = GetFieldOrProperty(hitbox, "activeDuration");
|
|
|
|
|
Assert.IsNotNull(duration, "AttackHitbox.activeDuration 필드/프로퍼티 접근 불가");
|
|
|
|
|
Assert.Greater(System.Convert.ToSingle(duration), 0f,
|
2026-04-23 14:47:51 +00:00
|
|
|
"activeDuration 가 0 이하면 OverlapBox 판정이 즉시 종료되어 공격 무효.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Enemy_Prefab_Has_Health_Component()
|
|
|
|
|
{
|
|
|
|
|
var prefab = AssetDatabase.LoadAssetAtPath<GameObject>(EnemyPrefabPath);
|
|
|
|
|
Assert.IsNotNull(prefab, $"Enemy.prefab not found at {EnemyPrefabPath}");
|
|
|
|
|
|
2026-04-23 14:50:20 +00:00
|
|
|
var health = FindComponentByFullName(prefab, HealthType);
|
2026-04-23 14:47:51 +00:00
|
|
|
Assert.IsNotNull(health,
|
|
|
|
|
"Enemy.prefab 에 Health 컴포넌트 누락. " +
|
|
|
|
|
"BT5-Dev 2단계 재위임 집행분 (2026-04-23) 이 prefab YAML 에 반영되어야 함. " +
|
|
|
|
|
"Health 없으면 AttackHitbox.Update 의 Decrement 호출이 불가 → EnemyDeath 체인 미발동.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Enemy_Prefab_Health_MaxHP_Is_One()
|
|
|
|
|
{
|
|
|
|
|
var prefab = AssetDatabase.LoadAssetAtPath<GameObject>(EnemyPrefabPath);
|
2026-04-23 14:50:20 +00:00
|
|
|
var health = FindComponentByFullName(prefab, HealthType);
|
2026-04-23 14:47:51 +00:00
|
|
|
Assert.IsNotNull(health);
|
|
|
|
|
|
2026-04-23 14:50:20 +00:00
|
|
|
var maxHP = GetFieldOrProperty(health, "maxHP");
|
|
|
|
|
Assert.IsNotNull(maxHP, "Health.maxHP 필드/프로퍼티 접근 불가");
|
|
|
|
|
Assert.AreEqual(1, System.Convert.ToInt32(maxHP),
|
2026-04-23 14:47:51 +00:00
|
|
|
"일반 적 기본 maxHP 1 (코어 룰 7 정합, 첫 세팅).");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Enemy_Prefab_Has_EnemyController_Component()
|
|
|
|
|
{
|
|
|
|
|
var prefab = AssetDatabase.LoadAssetAtPath<GameObject>(EnemyPrefabPath);
|
2026-04-23 14:50:20 +00:00
|
|
|
var controller = FindComponentByFullName(prefab, EnemyControllerType);
|
2026-04-23 14:47:51 +00:00
|
|
|
Assert.IsNotNull(controller,
|
|
|
|
|
"EnemyDeath 체인에 EnemyController 필수 (AttackHitbox.Update 에서 Schedule<EnemyDeath>().enemy = enemy).");
|
|
|
|
|
}
|
|
|
|
|
}
|