feat(enemy): 嘲风迁移到新轨——能力资产 + 对象树 + 开战触发

删 5 个空 BossSkillSO,用向导重建 6 个 EnemyAbilitySO(含入场演出)。
预制体经放置工具重新产出:EnemyAiBrain(_definitionId=ChaoFeng) +
BossPhaseAbilityGate + 6 个能力组件,不再有 BossSkillExecutor。
TestRoomA 加开战触发区。三件自检 0 error,EditMode 260/260。

首次真正跑通两条脚手架,暴露并修掉三个它们的缺陷:

1. 放置工具漏挂 EnemyLocomotion(PlaceChaoFeng 及其余 7 个敌人放置入口)。
   EnemyBase.Awake 找不到它即报错且 Locomotion 为 null,
   AiStateFragments.ApplyLocomotion 直接 NRE、AiRuntime 构造失败——
   Boss 建不出决策层,完全不动。已在所有敌人放置入口补齐。
2. 向导把空中阶段的 wind_stone 建成 requiresGrounded=true(SO 默认值)。
   Boss 浮空后 IsGrounded 恒 false,选招器把它滤掉,空中阶段站着不打。
   能力定义表加 grounded 列,阶段 1 的招显式置 false。
3. BossPhaseAbilityGate.ApplyPhase 只在 EnterPhase 与 OnSpawn 调用,
   直接摆场景里的 Boss 两条路径都不走,开局后续阶段的招仍在候选池里。
   BossBase.Start 补一次初始阶段应用。

另:Phase1_Tornado_HitBox 确认零消费者(龙卷判定随弹体走),
从放置工具删除其创建与伤害源绑定;
EnemyBrainContext.UseAbility 对解析不到的能力 id 改为 LogError,
不再静默返回 false(CLAUDE.md 第 6 条);
新增 PlaceBossFightTrigger 脚手架(此前无对应创建入口,属裸建)。

播放模式实测状态序列(TestRoomA,玩家走进触发区):
Wait →(Engaged) Intro → Ground⇄GroundAttack →(hp<50%) PhaseTransition
→ Air⇄AirAttack,浮空生效,阶段门按阶段换池,全程 0 报错。
动画 Clip 未接入,PlayClipAbility 空 clip 立即完成,故只验证了状态流转,
判定时序待美术接入后再校。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-30 16:02:14 +08:00
co-authored by Claude Opus 5
parent bdeefca75b
commit 877d2f5fef
13 changed files with 844 additions and 273 deletions
@@ -328,12 +328,12 @@ namespace BaseGames.Editor
var factory = MakeActionGroup();
factory.Add(MakeFactoryButton("ENM_ChaoFeng_Stats.asset", () => { CreateChaoFengStatsSO(); RefreshSOStatus(); }));
factory.Add(MakeFactoryButton("ENM_ChaoFeng_AnimConfig.asset",() => { CreateChaoFengAnimConfigSO(); RefreshSOStatus(); }));
foreach (var (abName, abId, soType, r, cd, w, ph) in ChaoFengAbilityDefs)
foreach (var (abName, abId, soType, r, cd, w, ph, g) in ChaoFengAbilityDefs)
{
string cName = abName; string cId = abId; System.Type cType = soType;
float cR = r, cCd = cd, cW = w; int cPh = ph;
float cR = r, cCd = cd, cW = w; int cPh = ph; bool cG = g;
factory.Add(MakeFactoryButton($"ABL_ChaoFeng_{cName}.asset",
() => { CreateChaoFengAbilitySO(cName, cId, cType, cR, cCd, cW, cPh); RefreshSOStatus(); }));
() => { CreateChaoFengAbilitySO(cName, cId, cType, cR, cCd, cW, cPh, cG); RefreshSOStatus(); }));
}
root.Add(factory);
@@ -691,7 +691,7 @@ namespace BaseGames.Editor
private static void CreateChaoFengAbilitySO(
string abilityName, string abilityId, System.Type soType,
float rangeRadius, float cooldown, float weight, int phase)
float rangeRadius, float cooldown, float weight, int phase, bool requiresGrounded)
{
const string dir = "Assets/_Game/Data/Enemies/ChaoFeng/Abilities";
string name = $"ABL_ChaoFeng_{abilityName}";
@@ -704,6 +704,9 @@ namespace BaseGames.Editor
? "入场演出,不进选招池"
: $"阶段 {phase} 招式;阶段可用性由 BossPhaseAbilityGate 配置";
so.cooldown = cooldown;
// 空中阶段的招必须放开这一项:选招器把 requiresGrounded 当硬门,
// Boss 浮空时 IsGrounded 恒为 false,留着默认 true 会让该招永远选不中。
so.requiresGrounded = requiresGrounded;
if (phase < 0)
{
@@ -727,25 +730,27 @@ namespace BaseGames.Editor
/// (见放置工具 PlaceChaoFeng),这里只记录供说明文本使用。
/// rangeRadius 必须 &gt; 0category==Attack 且射程为 0 的招永远够不着玩家,
/// EnemyAbilitySO.Validate 与 EnemyBase.BuildAttackSelector 都会显式报错。
/// grounded 是选招器的硬门:阶段 1 是空中阶段(Boss 浮空,IsGrounded 恒 false),
/// 该阶段的招必须为 false,否则永远选不中,空中阶段会站着不打。
/// </summary>
private static readonly (string name, string id, System.Type soType,
float rangeRadius, float cooldown, float weight, int phase)[]
float rangeRadius, float cooldown, float weight, int phase, bool grounded)[]
ChaoFengAbilityDefs =
{
("Intro", "chaofeng_intro", typeof(PlayClipAbilitySO), 0f, 0f, 0f, -1),
("Boomerang", "boomerang", typeof(PlayClipAbilitySO), 9f, 4.0f, 1.0f, 0),
("FanCombo", "fan_combo", typeof(EnemyAbilitySO), 2.5f, 2.5f, 1.5f, 0),
("TornadoSmall", "tornado_small", typeof(PlayClipAbilitySO), 8f, 3.5f, 1.2f, 0),
("TornadoLarge", "tornado_large", typeof(PlayClipAbilitySO), 12f, 6.0f, 0.8f, 0),
("WindStone", "wind_stone", typeof(PlayClipAbilitySO), 12f, 3.0f, 1.0f, 1),
("Intro", "chaofeng_intro", typeof(PlayClipAbilitySO), 0f, 0f, 0f, -1, true),
("Boomerang", "boomerang", typeof(PlayClipAbilitySO), 9f, 4.0f, 1.0f, 0, true),
("FanCombo", "fan_combo", typeof(EnemyAbilitySO), 2.5f, 2.5f, 1.5f, 0, true),
("TornadoSmall", "tornado_small", typeof(PlayClipAbilitySO), 8f, 3.5f, 1.2f, 0, true),
("TornadoLarge", "tornado_large", typeof(PlayClipAbilitySO), 12f, 6.0f, 0.8f, 0, true),
("WindStone", "wind_stone", typeof(PlayClipAbilitySO), 12f, 3.0f, 1.0f, 1, false),
};
private static void CreateAllChaoFengSOs()
{
CreateChaoFengStatsSO();
CreateChaoFengAnimConfigSO();
foreach (var (n, id, t, r, cd, w, ph) in ChaoFengAbilityDefs)
CreateChaoFengAbilitySO(n, id, t, r, cd, w, ph);
foreach (var (n, id, t, r, cd, w, ph, g) in ChaoFengAbilityDefs)
CreateChaoFengAbilitySO(n, id, t, r, cd, w, ph, g);
AssetDatabase.SaveAssets();
EditorUtility.DisplayDialog("创建完成",
"全部嘲风 SO 已创建(已存在的跳过)。\n" +
@@ -825,7 +830,7 @@ namespace BaseGames.Editor
("ENM_ChaoFeng_Stats", FindAtPath<EnemyStatsSO>($"{dir}/ENM_ChaoFeng_Stats.asset")),
("ENM_ChaoFeng_AnimConfig",FindAtPath<EnemyAnimationConfigSO>($"{dir}/ENM_ChaoFeng_AnimConfig.asset")),
};
foreach (var (abName, _, _, _, _, _, _) in ChaoFengAbilityDefs)
foreach (var (abName, _, _, _, _, _, _, _) in ChaoFengAbilityDefs)
checks.Add(($"ABL_ChaoFeng_{abName}",
FindAtPath<EnemyAbilitySO>($"{ablDir}/ABL_ChaoFeng_{abName}.asset")));
@@ -302,6 +302,7 @@ namespace BaseGames.Editor
EnemyStats enemyStats = GetOrAddComponent<EnemyStats>(go);
EnemyMovement movement = GetOrAddComponent<EnemyMovement>(go);
GetOrAddComponent<BaseGames.Enemies.Navigation.GroundNavigator>(go); // 地面导航(直接移动,无寻路图)
GetOrAddComponent<EnemyLocomotion>(go); // 移动执行器:EnemyBase.Awake 必须找得到,否则 AI 图的移动意图无处落地
PhysicsPerceptionSystem sensorHub = GetOrAddComponent<PhysicsPerceptionSystem>(go);
var (hurtBox, bodyContact, contactHitBox) =
@@ -445,6 +446,7 @@ namespace BaseGames.Editor
EnemyStats enemyStats = GetOrAddComponent<EnemyStats>(go);
EnemyMovement movement = GetOrAddComponent<EnemyMovement>(go);
GetOrAddComponent<BaseGames.Enemies.Navigation.GroundNavigator>(go); // 地面导航(直接移动,无寻路图)
GetOrAddComponent<EnemyLocomotion>(go); // 移动执行器:EnemyBase.Awake 必须找得到,否则 AI 图的移动意图无处落地
PhysicsPerceptionSystem sensorHub = GetOrAddComponent<PhysicsPerceptionSystem>(go);
var (hurtBox, bodyContact, contactHitBox) =
@@ -493,9 +495,7 @@ namespace BaseGames.Editor
SetupPerceptionSystemSlots(sensorHub, new[] { "aggro", "los" }, report);
GetOrAddComponent<EnemyLocomotion>(go);
// BrainGraph AI:挂载决策组件并绑定 AI 配方资产(取代旧的 Opsive BehaviorTree
// BrainGraph AI:挂载决策组件并绑定 AI 配方资产
var brain = GetOrAddComponent<EnemyAiBrain>(go);
var recipe = AssetDatabase.LoadAssetAtPath<PerceptionRecipeSO>(
"Assets/_Game/Data/Enemies/E001/ENM_E001_Ai.asset");
@@ -550,6 +550,7 @@ namespace BaseGames.Editor
EnemyStats enemyStats = GetOrAddComponent<EnemyStats>(go);
EnemyMovement movement = GetOrAddComponent<EnemyMovement>(go);
GetOrAddComponent<BaseGames.Enemies.Navigation.GroundNavigator>(go); // 地面导航(直接移动,无寻路图)
GetOrAddComponent<EnemyLocomotion>(go); // 移动执行器:EnemyBase.Awake 必须找得到,否则 AI 图的移动意图无处落地
PhysicsPerceptionSystem sensorHub = GetOrAddComponent<PhysicsPerceptionSystem>(go);
// HurtBox + ContactDamageZone(身体接触伤害常驻开启;HurtBox 悬挂期外关闭见下)
@@ -651,6 +652,7 @@ namespace BaseGames.Editor
EnemyStats enemyStats = GetOrAddComponent<EnemyStats>(go);
EnemyMovement movement = GetOrAddComponent<EnemyMovement>(go);
GetOrAddComponent<BaseGames.Enemies.Navigation.GroundNavigator>(go); // 地面导航(直接移动,无寻路图)
GetOrAddComponent<EnemyLocomotion>(go); // 移动执行器:EnemyBase.Awake 必须找得到,否则 AI 图的移动意图无处落地
PhysicsPerceptionSystem sensorHub = GetOrAddComponent<PhysicsPerceptionSystem>(go);
var (hurtBox, bodyContact, contactHitBox) =
@@ -741,6 +743,7 @@ namespace BaseGames.Editor
EnemyFeedback feedback = GetOrAddComponent<EnemyFeedback>(go);
EnemyMovement movement = GetOrAddComponent<EnemyMovement>(go);
GetOrAddComponent<BaseGames.Enemies.Navigation.GroundNavigator>(go); // 地面导航(直接移动,无寻路图)
GetOrAddComponent<EnemyLocomotion>(go); // 移动执行器:EnemyBase.Awake 必须找得到,否则 AI 图的移动意图无处落地
PhysicsPerceptionSystem sensorHub = GetOrAddComponent<PhysicsPerceptionSystem>(go);
var (hurtBox, bodyContact, contactHitBox) =
@@ -871,6 +874,7 @@ namespace BaseGames.Editor
EnemyStats enemyStats = GetOrAddComponent<EnemyStats>(go);
EnemyMovement movement = GetOrAddComponent<EnemyMovement>(go);
GetOrAddComponent<BaseGames.Enemies.Navigation.GroundNavigator>(go); // 地面导航(直接移动,无寻路图)
GetOrAddComponent<EnemyLocomotion>(go); // 移动执行器:EnemyBase.Awake 必须找得到,否则 AI 图的移动意图无处落地
PhysicsPerceptionSystem sensorHub = GetOrAddComponent<PhysicsPerceptionSystem>(go);
var (hurtBox, bodyContact, contactHitBox) =
@@ -982,6 +986,7 @@ namespace BaseGames.Editor
EnemyStats enemyStats = GetOrAddComponent<EnemyStats>(go);
EnemyMovement movement = GetOrAddComponent<EnemyMovement>(go);
GetOrAddComponent<BaseGames.Enemies.Navigation.GroundNavigator>(go); // 地面导航(直接移动,无寻路图)
GetOrAddComponent<EnemyLocomotion>(go); // 移动执行器:EnemyBase.Awake 必须找得到,否则 AI 图的移动意图无处落地
PhysicsPerceptionSystem sensorHub = GetOrAddComponent<PhysicsPerceptionSystem>(go);
var (hurtBox, bodyContact, contactHitBox) =
@@ -1084,6 +1089,10 @@ namespace BaseGames.Editor
EnemyFeedback feedback = GetOrAddComponent<EnemyFeedback>(go);
EnemyMovement movement = GetOrAddComponent<EnemyMovement>(go);
GetOrAddComponent<BaseGames.Enemies.Navigation.GroundNavigator>(go); // 地面导航(直接移动,无寻路图)
// 移动执行器:AI 图的移动意图(Idle/Face/Approach)全靠它落地。
// 少了它 EnemyBase.Awake 就报「未找到 EnemyLocomotion」,且 Locomotion 为 null
// 建图时 AiStateFragments.ApplyLocomotion 会 NREAiRuntime 构造失败 → Boss 完全不动。
GetOrAddComponent<EnemyLocomotion>(go);
EnemyAiBrain brain = GetOrAddComponent<EnemyAiBrain>(go);
BossPhaseAbilityGate phaseGate = GetOrAddComponent<BossPhaseAbilityGate>(go);
ChaoFengFloatController floatCtrl = GetOrAddComponent<ChaoFengFloatController>(go);
@@ -1094,16 +1103,16 @@ namespace BaseGames.Editor
var (hurtBox, bodyContact, contactHitBox) =
SetupHurtAndContactBoxes(go, size, report);
// Phase1 攻击 HitBox(默认禁用;由能力按 EnemyAttackSO.hitBoxSlot 归一化时机开关)。
// 计划:挥扇三连 FanCombo ×3 + 龙卷接触 Tornado。
// 近战攻击 HitBox(默认禁用;由 MeleeAttackAbility 按 EnemyAttackSO.hitBoxSlot 归一化时机开关)。
// 只有挥扇三连需要 Boss 自身的判定;回旋扇 / 龙卷 / 风石都是弹体招,
// 判定随 SpawnProjectile 动画事件生成的弹体走,Boss 身上不留对应 HitBox
// (留一个无人引用的 HitBox 会让作者误以为该招判定挂在 Boss 身上)。
HitBox fan1 = CreateDisabledHitBox(go.transform, "Phase1_FanCombo_HitBox_1", "EnemyHitBox",
true, report, size: new Vector2(1.0f, 0.5f));
HitBox fan2 = CreateDisabledHitBox(go.transform, "Phase1_FanCombo_HitBox_2", "EnemyHitBox",
true, report, size: new Vector2(1.0f, 0.5f));
HitBox fan3 = CreateDisabledHitBox(go.transform, "Phase1_FanCombo_HitBox_3", "EnemyHitBox",
true, report, size: new Vector2(1.2f, 0.6f));
HitBox tornadoHB = CreateDisabledHitBox(go.transform, "Phase1_Tornado_HitBox", "EnemyHitBox",
true, report, size: new Vector2(0.6f, 1.2f));
// 弹体发射点(Phase1 回旋扇 / 龙卷;Phase2 风石)
Transform boomerangMuzzleT = GetOrCreateChild(go.transform, "BoomerangMuzzle");
@@ -1212,7 +1221,7 @@ namespace BaseGames.Editor
Object dmgSrc = FindFirstAsset("CMB_DS_BossBody", "CMB_DS_EnemyBody");
if (dmgSrc != null)
{
foreach (var hb in new[] { fan1, fan2, fan3, tornadoHB, contactHitBox })
foreach (var hb in new[] { fan1, fan2, fan3, contactHitBox })
if (hb != null) AssignReference(hb, "_defaultSource", dmgSrc, report);
}
@@ -1235,6 +1244,75 @@ namespace BaseGames.Editor
MarkDirtyAndLog("Boss 嘲风 (ChaoFeng)", go, report);
}
[MenuItem("BaseGames/Scene/Place/Boss 开战触发区 (嘲风)", priority = 118)]
public static void PlaceChaoFengFightTrigger() => PlaceBossFightTrigger("ChaoFeng");
/// <summary>
/// 放置 Boss 开战触发区:玩家进入即广播开战事件并让 Boss 决策层进战。
/// 没有它,Boss 会一直停在静置态——开战事件频道此前全项目零发送方。
/// </summary>
/// <param name="bossId">
/// Boss id。既写进触发器的 <c>_bossId</c>BGM / 血条按它定位 Boss),
/// 也用来在活动场景里定位目标 Boss——按 <c>EnemyAiBrain._definitionId</c> 匹配。
/// </param>
public static void PlaceBossFightTrigger(string bossId)
{
var report = new List<string>();
int undoGroup = Undo.GetCurrentGroup();
Undo.SetCurrentGroupName("Place Boss Fight Trigger");
GameObject go = new GameObject($"BossFightTrigger_{bossId}");
Undo.RegisterCreatedObjectUndo(go, "Place Boss Fight Trigger");
go.transform.position = GetDropPosition();
SetLayer(go, "TriggerZone", report);
// 碰撞体必须先于 BossFightTrigger 挂上:该组件标了 [RequireComponent(typeof(Collider2D))]
// 而 Collider2D 是抽象类,Unity 补不出来,AddComponent 会返回真正的 null。
BoxCollider2D col = GetOrAddComponent<BoxCollider2D>(go);
col.isTrigger = true;
col.size = new Vector2(4f, 6f); // 门口尺寸占位,按竞技场入口在 Inspector 调整
BossFightTrigger trigger = GetOrAddComponent<BossFightTrigger>(go);
AssignString(trigger, "_bossId", bossId, report);
AssignLayerMask(trigger, "_playerLayers", "Player", report);
AssignAsset(trigger, "_onBossFightStarted", report, true, "EVT_BossFightStarted");
// 开关频道:资产名叫 EVT_BossFightEnded,但实际是「战斗中 true/false」的开关,
// BGMController 与 BossHPBar 绑的也是它。名字与用途不符是既存问题,此处沿用同一资产。
AssignAsset(trigger, "_onBossFightToggled", report, true, "EVT_BossFightEnded");
// 目标 Boss:按 EnemyAiBrain._definitionId 在活动场景里精确匹配,不做名字模糊猜测。
// 匹配不到(或匹配到多个)一律如实报告,不塞一个凑数的引用——
// 漏绑时 BossFightTrigger.Awake 也会再报一次并停用自己。
var matches = new List<EnemyAiBrain>();
foreach (var root in UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene().GetRootGameObjects())
foreach (var b in root.GetComponentsInChildren<EnemyAiBrain>(true))
if (new SerializedObject(b).FindProperty("_definitionId")?.stringValue == bossId)
matches.Add(b);
if (matches.Count == 1)
{
AssignReference(trigger, "_bossBrain", matches[0], report);
report.Add($"[OK] _bossBrain → {matches[0].name}_definitionId={bossId}");
}
else if (matches.Count == 0)
{
report.Add($"✗ 活动场景里找不到 _definitionId={bossId} 的 EnemyAiBrain" +
"_bossBrain 未绑定。请先放置该 Boss,再重跑本操作。");
}
else
{
report.Add($"✗ 活动场景里有 {matches.Count} 个 _definitionId={bossId} 的 EnemyAiBrain" +
"无法确定目标,_bossBrain 未绑定。请先清理重复的 Boss。");
}
report.Add("★ 把触发区拖到竞技场入口并按门口尺寸调整 BoxCollider2D。只触发一次。");
Undo.CollapseUndoOperations(undoGroup);
Selection.activeGameObject = go;
MarkDirtyAndLog($"Boss 开战触发区 ({bossId})", go, report);
}
// ══ 敌人放置辅助方法 ═══════════════════════════════════════════════════
/// <summary>
@@ -67,10 +67,26 @@ namespace BaseGames.Enemies
public Vector2 LastKnown => _lastKnown;
// ---- ICombatant ----
/// <summary>
/// 执行指定 id 的能力。解析不到该 id 一律显式报错——
/// 建图期 <c>AiStateFragments.Ability/AbilityOnce</c> 已挡掉空 id
/// 所以运行期解析不到只可能是漏挂能力组件或 SO 上的 abilityId 写错,没有合法情形。
/// 静默返回 false 会让「能力态进入后什么都不做、IsAbilityRunning 恒假、
/// 完成条件立刻成立」表现为"演出被跳过"却零报错(CLAUDE.md 第 6 条)。
/// 用 LogError 而非抛异常:这是每帧路径,抛异常会打断整个 AiRuntime.Tick
/// 让一个漏配的敌人拖垮整场战斗。
/// </summary>
public bool UseAbility(string abilityId)
{
var a = _enemy.Abilities?.Get(abilityId);
return a != null && a.Execute();
if (a == null)
{
Debug.LogError($"[EnemyBrainContext] '{_enemy.name}' 的 AI 图请求能力 " +
$"'{abilityId}',但该敌人身上没有这个能力组件。" +
"请检查能力组件是否挂载、其 EnemyAbilitySO 的 abilityId 是否一致。", _enemy);
return false;
}
return a.Execute();
}
public bool IsAbilityRunning(string abilityId = null)
{
@@ -86,6 +86,16 @@ namespace BaseGames.Enemies
if (_arenaAnchors == null) _arenaAnchors = GetComponentInChildren<BossArenaAnchors>(true);
}
// 初始阶段的招池必须在第一次选招前就位。
// ApplyPhase 此前只在 EnterPhase(阶段切换)与 OnSpawn(对象池复用)里调用,
// 而直接摆在场景里的 Boss 两条路径都不走——开局时后续阶段的招式仍是 enabled,
// 会混进阶段 0 的候选池。放在 Start:此时各能力组件的 Awake 均已执行完毕。
protected override void Start()
{
base.Start();
_phaseGate?.ApplyPhase(_currentPhase);
}
protected override void OnEnable()
{
base.OnEnable();