refactor(enemy): 敌人专属子类改为零代码配置型行为组件

This commit is contained in:
2026-06-09 15:56:44 +08:00
parent 7781ac4755
commit ebf0c97320
22 changed files with 496 additions and 242 deletions

View File

@@ -10,6 +10,7 @@ using BaseGames.Core.Pool;
using BaseGames.Dialogue;
using BaseGames.Enemies;
using BaseGames.Enemies.Abilities;
using BaseGames.Enemies.Behaviors;
using BaseGames.Enemies.Boss;
using BaseGames.Enemies.Navigation;
using BaseGames.Enemies.Perception;
@@ -638,7 +639,7 @@ namespace BaseGames.Editor
AnimancerComponent animancer = GetOrAddComponent<AnimancerComponent>(visual.gameObject);
SpriteRenderer sr3 = SetupSpriteRenderer(visual.gameObject);
E003_YouZhi enemyBase = GetOrAddComponent<E003_YouZhi>(go);
EnemyBase enemyBase = GetOrAddComponent<EnemyBase>(go);
EnemyStats enemyStats = GetOrAddComponent<EnemyStats>(go);
EnemyMovement movement = GetOrAddComponent<EnemyMovement>(go);
GetOrAddComponent<EnemyNavAgent>(go);
@@ -691,12 +692,17 @@ namespace BaseGames.Editor
AssignAsset(fallAbility, "_config", report, false, "ABL_E003_Fall");
AssignReference(fallAbility, "_contactDamage", bodyContact, report);
// 出生 / 外部触发执行下坠能力(零代码:替代过去的 E003_YouZhi 专属脚本)
EnemyAbilityTrigger fallTrigger = GetOrAddComponent<EnemyAbilityTrigger>(go);
AssignString(fallTrigger, "_abilityId", "e003_fall", report);
AssignBool(fallTrigger, "_executeOnSpawn", true);
Object dmgSrc = FindFirstAsset("CMB_DS_EnemyBody");
if (dmgSrc != null) AssignReference(contactHitBox, "_defaultSource", dmgSrc, report);
SetupPerceptionSystemSlots(sensorHub, new[] { "aggro", "los" }, report);
report.Add("★ 将此对象放置于天花板下方E003_YouZhi 会在 OnSpawn/ActivateFromCeiling 时执行下坠。");
report.Add("★ 挂载行为树 BehaviorTree 组件,指定 E003_YouZhi.asset。");
report.Add("★ 将此对象放置于天花板下方EnemyAbilityTrigger 在出生时(executeOnSpawn)自动、或被场景触发器调用 Trigger() 时执行下坠能力(e003_fall)。");
report.Add("★ 挂载行为树 BehaviorTree 组件,指定对应外部行为树资产。");
Undo.CollapseUndoOperations(undoGroup);
Selection.activeGameObject = go;
@@ -731,7 +737,7 @@ namespace BaseGames.Editor
AnimancerComponent animancer = GetOrAddComponent<AnimancerComponent>(visual.gameObject);
SpriteRenderer sr4 = SetupSpriteRenderer(visual.gameObject);
E004_ZhiMu enemyBase = GetOrAddComponent<E004_ZhiMu>(go);
EnemyBase enemyBase = GetOrAddComponent<EnemyBase>(go);
EnemyStats enemyStats = GetOrAddComponent<EnemyStats>(go);
EnemyFeedback feedback = GetOrAddComponent<EnemyFeedback>(go);
EnemyMovement movement = GetOrAddComponent<EnemyMovement>(go);
@@ -819,10 +825,14 @@ namespace BaseGames.Editor
AssignReference(slamHitBox, "_defaultSource", dmgSrc, report);
}
// 死亡前摇无敌演出(零代码:替代过去的 E004_ZhiMu 专属 Die() 重写)
EnemyDeathSequence deathSeq = GetOrAddComponent<EnemyDeathSequence>(go);
AssignObjectArray(deathSeq, "_hurtBoxesToDisable", new Object[] { hurtBox }, report);
SetupPerceptionSystemSlots(sensorHub, new[] { "aggro", "attack_melee", "attack_range", "sight" }, report);
report.Add("★ AppearAbility._appearClip / FacePlayerAbility._faceClip 等动画 Clip 待美术接入后在 Inspector 指定。");
report.Add("★ 在 E004_ZhiMu._deathPreClip 配置死亡前摇动画(两阶段死亡 Death_Pre 无敌)。");
report.Add("★ 挂载行为树 BehaviorTree 组件,指定 E004_ZhiMu.asset。");
report.Add("★ 在 EnemyDeathSequence._deathPreClip 配置死亡前摇动画(两阶段死亡 Death_Pre 无敌)。");
report.Add("★ 挂载行为树 BehaviorTree 组件,指定对应外部行为树资产。");
Undo.CollapseUndoOperations(undoGroup);
Selection.activeGameObject = go;
@@ -857,7 +867,7 @@ namespace BaseGames.Editor
AnimancerComponent animancer = GetOrAddComponent<AnimancerComponent>(visual.gameObject);
SpriteRenderer sr5 = SetupSpriteRenderer(visual.gameObject);
E005_FeiZhi enemyBase = GetOrAddComponent<E005_FeiZhi>(go);
EnemyBase enemyBase = GetOrAddComponent<EnemyBase>(go);
EnemyStats enemyStats = GetOrAddComponent<EnemyStats>(go);
EnemyMovement movement = GetOrAddComponent<EnemyMovement>(go);
GetOrAddComponent<EnemyNavAgent>(go);
@@ -920,9 +930,16 @@ namespace BaseGames.Editor
Object dmgSrc = FindFirstAsset("CMB_DS_EnemyBody");
if (dmgSrc != null) AssignReference(biteHitBox, "_defaultSource", dmgSrc, report);
// 死亡前摇无敌演出 + 动画事件池生成幼蛭(零代码:替代过去的 E005_FeiZhi 专属 Die()/SpawnProjectile 重写)
EnemyDeathSequence deathSeq = GetOrAddComponent<EnemyDeathSequence>(go);
AssignObjectArray(deathSeq, "_hurtBoxesToDisable", new Object[] { hurtBox }, report);
EnemySpawnerOnEvent spawner = GetOrAddComponent<EnemySpawnerOnEvent>(go);
AssignString(spawner, "_payloadKey", "spawn_e003", report);
AssignString(spawner, "_poolKey", "ENM_YouZhi", report);
SetupPerceptionSystemSlots(sensorHub, new[] { "aggro", "attack_melee", "attack_range", "los" }, report);
report.Add("★ 在 E005_FeiZhi._deathPreClip 上添加 AnimationEvent 调用 SpawnProjectile(\"spawn_e003\")。");
report.Add("★ 挂载行为树 BehaviorTree 组件,指定 E005_FeiZhi.asset。");
report.Add("★ 在 EnemyDeathSequence._deathPreClip 上添加 AnimationEvent 调用 SpawnProjectile(\"spawn_e003\"),由 EnemySpawnerOnEvent 从对象池生成幼蛭(ENM_YouZhi)。");
report.Add("★ 挂载行为树 BehaviorTree 组件,指定对应外部行为树资产。");
Undo.CollapseUndoOperations(undoGroup);
Selection.activeGameObject = go;