using Photon.Deterministic; using System; namespace Quantum { public static unsafe partial class BTManager { public static Action OnSetupDebugger; public static Action OnNodeEnter; public static Action OnNodeExit; public static Action OnNodeSuccess; public static Action OnNodeFailure; public static Action OnDecoratorChecked; public static Action OnDecoratorReset; public static Action OnTreeCompleted; /// /// Call this once, to initialize the BTAgent. /// This method internally looks for a Blackboard Component on the entity /// and passes it down the pipeline. /// /// /// /// public static void Init(Frame frame, EntityRef entity, BTRoot root) { if (frame.Unsafe.TryGetPointer(entity, out BTAgent* agent)) { agent->Initialize(frame, entity, agent, root, true); } else { Log.Error("[Bot SDK] Tried to initialize an entity which has no BTAgent component"); } } /// /// Made for internal use only. /// public static void ClearBTParams(BTParams btParams) { btParams.Reset(btParams.Frame); } /// /// Call this method every frame to update your BT Agent. /// You can optionally pass a Blackboard Component to it, if your Agent use it /// public static void Update(Frame frame, EntityRef entity, AIBlackboardComponent* blackboard = null) { var agent = frame.Unsafe.GetPointer(entity); BTParams btParams = new BTParams(); btParams.SetDefaultParams(frame, agent, entity, blackboard); agent->Update(ref btParams); } /// /// CAUTION: Use this overload with care.
/// It allows the definition of custom parameters which are passed through the entire BT pipeline, for easy access.
/// The user parameters struct needs to be created from scratch every time BEFORE calling the BT Update method.
/// Make sure to also implement BTParamsUser.ClearUser(frame). ///
/// Used to define custom user data. It needs to be created from scratch every time before calling this method. public static void Update(Frame frame, EntityRef entity, ref BTParamsUser userParams, AIBlackboardComponent* blackboard = null) { var agent = frame.Unsafe.GetPointer(entity); BTParams btParams = new BTParams(); btParams.SetDefaultParams(frame, agent, entity, blackboard); btParams.UserParams = userParams; agent->Update(ref btParams); } } }