30 lines
1.1 KiB
C#
30 lines
1.1 KiB
C#
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;
|
|
}
|
|
}
|