feat(enemy): PerceptionRecipeSO 配方资产 + SubclassSelector 模块下拉

未发现层/交战层各用 [SerializeReference]+[SubclassSelector] 下拉挑选模块,
新增模块类自动出现在下拉里,无需改枚举或已有文件。默认交战模块仍为
RushEngagement——未配能力时建图必须显式报错,而非静默产出打不出手的图。
This commit is contained in:
2026-07-29 14:46:41 +08:00
parent 04f644969b
commit 825cae7977
10 changed files with 298 additions and 0 deletions
@@ -0,0 +1,10 @@
using UnityEngine;
namespace BaseGames.Enemies
{
/// <summary>
/// 标在 [SerializeReference] 字段上,Inspector 里给出该接口所有 [Serializable] 实现的下拉。
/// 意义:新增一个模块类,它自动出现在所有配方的下拉里,无需改枚举或任何已有文件。
/// </summary>
public sealed class SubclassSelectorAttribute : PropertyAttribute { }
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c3ac40bfbd1059347b817809c1347d6d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: fc5a433d5f1395e458987409609cc01e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,32 @@
using UnityEngine;
using BaseGames.AI;
namespace BaseGames.Enemies
{
/// <summary>
/// 感知型 AI 配方:一个 SO 类型覆盖所有走「未发现 → 警觉 → 交战」规则的敌人。
/// 两个下拉各选一个模块即可,无需写代码。有独门机制的敌人改写 AiScript 子类。
/// </summary>
[CreateAssetMenu(menuName = "BaseGames/AI/感知型 AI 配方", fileName = "ENM_")]
public sealed class PerceptionRecipeSO : AiRecipeSO
{
[Tooltip("未发现层:玩家尚未被发现时的行为形状")]
[SerializeReference, SubclassSelector] IUnawareModule _unaware = new SinglePost();
[Tooltip("交战层:发现玩家之后怎么打")]
[SerializeReference, SubclassSelector] IEngagementModule _engagement = new RushEngagement();
// 无「死亡层」字段:死亡归物理层,骨架自己声明 Death 终态。
// PerformDeath 先 ForceState(Dead) 再发 Died 信号,此后 IsControllable 永久为假,
// 死亡链里的条件边永不被求值——所以死亡不能做成可插拔层。
protected override void Build(BrainBuilder b)
=> PerceptionSkeleton.Add(b, _unaware, _engagement);
/// <summary>仅供 EditMode 测试与脚手架向导装配模块,运行时不使用。</summary>
public void SetModulesForTests(IUnawareModule unaware, IEngagementModule engagement)
{
_unaware = unaware; _engagement = engagement;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0b849b67f708c3b4f9af91a9e5f2e546
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: