关于行为树可视化插件BehaviorDesigner

1、BehaviorTree的生命周期
// OnAwake is called once when the behavior tree is enabled. Think of it as a constructor public virtual void OnAwake(); // OnStart is called immediately before execution. It is used to setup any variables that need to be reset from the previous run public virtual void OnStart(); // OnUpdate runs the actual task public virtual TaskStatus OnUpdate(); // OnEnd is called after execution on a success or failure. public virtual void OnEnd(); // OnPause is called when the behavior is paused and resumed public virtual void OnPause(bool paused); // The priority select will need to know this tasks priority of running public virtual float GetPriority(); // OnBehaviorComplete is called after the behavior tree finishes executing public virtual void OnBehaviorComplete(); // OnReset is called by the inspector to reset the public properties public virtual void OnReset(); // Allow OnDrawGizmos to be called from the tasks public virtual void OnDrawGizmos(); // Keep a reference to the behavior that owns this task public Behavior Owner;
重点说明,尤其在有重复repeat节点时,OnAwake、OnStart、OnUpdate、OnEnd、OnPause 都是节点自身的生命周期的通知,而OnBehaviorComplete是整个行为树结束时对每个task的通知。
在debug明显可以看到OnAwake只执行一次,OnStart、OnUpdate、OnEnd会执行很多次(因为Repeat节点反复执行task),OnUpdate更特殊,如果return状态Runing会不停执行知道非Running。而OnBehaviorComplete是只在整个行为停止以后通知,可以代替普通MonoBehavior的OnDestroy来执行兜底清理逻辑。

浙公网安备 33010602011771号