feat(ai): BrainGraph Transition/AiState/TransitionRecord 数据结构
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BaseGames.AI
|
||||
{
|
||||
/// <summary>一个状态:进入/每帧/退出钩子 + 出边转换列表(按优先级有序,首个命中即转)。</summary>
|
||||
public sealed class AiState
|
||||
{
|
||||
public string Name { get; }
|
||||
public Action<IAiContext> OnEnter { get; internal set; }
|
||||
public Action<IAiContext, float> OnTick { get; internal set; } // (ctx, dt)
|
||||
public Action<IAiContext> OnExit { get; internal set; }
|
||||
public List<Transition> Transitions { get; } = new List<Transition>();
|
||||
|
||||
public AiState(string name) => Name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 630a7309ff643a04c9de5cd6ef43ded0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
|
||||
namespace BaseGames.AI
|
||||
{
|
||||
/// <summary>一条转换:条件型(Condition 非空)或事件型(Event 非空)。二者互斥。</summary>
|
||||
public sealed class Transition
|
||||
{
|
||||
public string Target { get; }
|
||||
public Func<IAiContext, bool> Condition { get; } // 条件型:pull,按 LOD 频率评估
|
||||
public AiSignal? Event { get; } // 事件型:push,收到信号即触发
|
||||
public string Label { get; } // 可读标签(显式字符串 / 事件名)
|
||||
|
||||
Transition(string target, Func<IAiContext, bool> condition, AiSignal? evt, string label)
|
||||
{
|
||||
Target = target;
|
||||
Condition = condition;
|
||||
Event = evt;
|
||||
Label = label;
|
||||
}
|
||||
|
||||
public static Transition OnCondition(string target, Func<IAiContext, bool> condition, string label)
|
||||
=> new Transition(target, condition, null, label);
|
||||
|
||||
public static Transition OnEvent(string target, AiSignal evt)
|
||||
=> new Transition(target, null, evt, "on " + evt);
|
||||
|
||||
public bool IsEvent => Event.HasValue;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de31e9d8e9d89574196fe5244fbdfb27
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace BaseGames.AI
|
||||
{
|
||||
/// <summary>一次已发生的转换,供调试器/MCP 自省"最近为何转换"。</summary>
|
||||
public readonly struct TransitionRecord
|
||||
{
|
||||
public readonly string From;
|
||||
public readonly string To;
|
||||
public readonly string Trigger; // 条件标签或事件名
|
||||
|
||||
public TransitionRecord(string from, string to, string trigger)
|
||||
{
|
||||
From = from;
|
||||
To = to;
|
||||
Trigger = trigger;
|
||||
}
|
||||
|
||||
public override string ToString() => $"{From} -> {To} : {Trigger}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 58fdd083866686f4e9c0008323c2773d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user