2026-03-20 12:07:44 -04:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using Opsive.BehaviorDesigner.Runtime;
|
|
|
|
|
|
using UnityEngine;
|
2026-05-10 11:47:55 -04:00
|
|
|
|
using UnityEngine.AI;
|
2026-03-20 12:07:44 -04:00
|
|
|
|
|
|
|
|
|
|
namespace Cielonos.MainGame.Characters
|
|
|
|
|
|
{
|
|
|
|
|
|
public class BehaviorSubcontroller : SubcontrollerBase<Automata>
|
|
|
|
|
|
{
|
|
|
|
|
|
public Automata Automata => owner;
|
|
|
|
|
|
|
|
|
|
|
|
public BehaviorTree mainBehaviorTree;
|
2026-05-10 11:47:55 -04:00
|
|
|
|
public NavMeshAgent navMeshAgent;
|
2026-03-20 12:07:44 -04:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|