Files
Cielonos/Assets/Scripts/MainGame/Characters/Automata/Submodules/BehaviorSubcontroller.cs
2026-05-10 11:47:55 -04:00

48 lines
1.6 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 System.Collections.Generic;
using Opsive.BehaviorDesigner.Runtime;
using UnityEngine;
using UnityEngine.AI;
namespace Cielonos.MainGame.Characters
{
public class BehaviorSubcontroller : SubcontrollerBase<Automata>
{
public Automata Automata => owner;
public BehaviorTree mainBehaviorTree;
public NavMeshAgent navMeshAgent;
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;
}
}
}