46 lines
1.5 KiB
C#
46 lines
1.5 KiB
C#
using System.Collections.Generic;
|
||
using Opsive.BehaviorDesigner.Runtime;
|
||
using UnityEngine;
|
||
|
||
namespace Cielonos.MainGame.Characters
|
||
{
|
||
public class BehaviorSubcontroller : SubcontrollerBase<Automata>
|
||
{
|
||
public Automata Automata => owner;
|
||
|
||
public BehaviorTree mainBehaviorTree;
|
||
public Dictionary<string, Subtree> subBehaviorTrees;
|
||
|
||
public class AutomataEvent
|
||
{
|
||
public float Timestamp;
|
||
public object Arg1;
|
||
public object Arg2;
|
||
public object Arg3;
|
||
|
||
public bool IsValid(float expireTime)
|
||
{
|
||
return Time.time - Timestamp <= expireTime;
|
||
}
|
||
}
|
||
|
||
// 以事件名称作为键值存储
|
||
public readonly Dictionary<string, AutomataEvent> EventMemory = new Dictionary<string, AutomataEvent>();
|
||
/// <summary>
|
||
/// 向自身的 AI 下达上下文事件通知(代替原生的 ExecuteEvent)
|
||
/// </summary>
|
||
public void DispatchContextEvent(string eventName, object arg1 = null, object arg2 = null, object arg3 = null)
|
||
{
|
||
if (!EventMemory.TryGetValue(eventName, out AutomataEvent e))
|
||
{
|
||
e = new AutomataEvent();
|
||
EventMemory[eventName] = e;
|
||
}
|
||
// 更新该事件发生的最绝对新时间与参数
|
||
e.Timestamp = Time.time;
|
||
e.Arg1 = arg1;
|
||
e.Arg2 = arg2;
|
||
e.Arg3 = arg3;
|
||
}
|
||
}
|
||
} |