Files
zeling_v2/Assets/_Game/Scripts/AI/AiRecipeSO.cs
T
joywayerandClaude Opus 5 04f644969b fix(ai): AiRecipeSO.OnEnable 改 protected virtual,防子类静默遮蔽
留作 private 时,子类另写一个 OnEnable 会遮蔽它(Unity 只调最派生的),
PlayModeResetHook 注册从此不发生且零报错——关闭域重载下即表现为
"改了配方进 Play 仍跑旧图"。T13 的 PerceptionRecipeSO 是第一个子类,
在它出现前先堵住。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-29 14:36:22 +08:00

42 lines
1.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using UnityEngine;
using BaseGames.Core.Events;
namespace BaseGames.AI
{
/// <summary>
/// AI 配方资产基类。子类以序列化字段描述一张图,Build 里组装。
/// 一个资产 = 一种敌人 AI;所有引用该资产的实例共享同一张 AiGraphflyweight)。
/// </summary>
public abstract class AiRecipeSO : ScriptableObject, IAiDefinition
{
AiGraph _cached;
/// <summary>
/// 子类若要自己的 OnEnable,必须 override 本方法并调 base.OnEnable()——
/// 声明成 protected virtual 正是为此:若留作 private,子类另写一个 OnEnable 会
/// 静默遮蔽它(Unity 只调最派生的那个),缓存清理从此不再注册且无任何报错。
/// </summary>
protected virtual void OnEnable()
{
// 项目已关闭 Domain ReloadSO 的运行时态在多次 Play 会话间会残留,
// 改了配方再进 Play 仍用旧图。登记到统一的"进入 Play 前重置"通道。
PlayModeResetHook.Register(ClearCache);
}
void ClearCache() => _cached = null;
public AiGraph GetOrBuildGraph()
{
if (_cached == null)
{
var b = new BrainBuilder();
Build(b);
_cached = b.Build();
}
return _cached;
}
protected abstract void Build(BrainBuilder b);
}
}