public void OnComplete(BehaviourTreeExecutor <TBlackboard> executor, BehaviourTreeExecutionData <TBlackboard> execution, BehaviourTreeStatus status) { if (status == BehaviourTreeStatus.Success) { ++execution.Variables[_succeededCountId]; if (SucceedPolicy == ParallelPolicy.RequireOne) { Stop(executor, execution, BehaviourTreeStatus.Success); return; } } else if (status == BehaviourTreeStatus.Failure) { ++execution.Variables[_failedCountId]; if (FailurePolicy == ParallelPolicy.RequireOne) { Stop(executor, execution, BehaviourTreeStatus.Failure); return; } } if (FailurePolicy == ParallelPolicy.RequireAll && execution.Variables[_failedCountId] == ChildrenCount) { Stop(executor, execution, BehaviourTreeStatus.Failure); } else if (SucceedPolicy == ParallelPolicy.RequireAll && execution.Variables[_succeededCountId] == ChildrenCount) { Stop(executor, execution, BehaviourTreeStatus.Success); } }
private bool Step(BehaviourTreeExecutionData <TBlackboard> data, TBlackboard blackboard) { var current = data.Stack.RemoveFront(); if (current == null) { return(false); } var status = current.Tick(this, data, blackboard); if (status != BehaviourTreeStatus.Running) { if (current.Observer != null) { current.Observer.OnComplete(this, data, status); } } else { data.Stack.AddBack(current); } return(true); }
private void Stop(BehaviourTreeExecutor <TBlackboard> executor, BehaviourTreeExecutionData <TBlackboard> data, BehaviourTreeStatus status) { AbortRunningChildren(executor, data); executor.Stop(data, this, status); }
public void Tick(BehaviourTreeExecutionData <TBlackboard> executionData, TBlackboard blackboard) { executionData.Stack.AddBack(null); while (Step(executionData, blackboard)) { } }
private static void RemoveNode(BehaviourTreeExecutionData <TBlackboard> data, BehaviourTreeNode <TBlackboard> node) { var index = data.Stack.IndexOf(node); if (index >= 0) { data.Stack.RemoveAt(index); } }
public void Schedule(BehaviourTreeExecutionData <TBlackboard> data, BehaviourTreeNode <TBlackboard> node, ICompletionObserver <TBlackboard> observer = null) { if (observer != null) { node.Observer = observer; } data.Stack.AddBack(node); }
public void AbortRunningChildren(BehaviourTreeExecutor <TBlackboard> executor, BehaviourTreeExecutionData <TBlackboard> data) { foreach (var node in Children) { if (node.IsRunning(data)) { executor.Abort(data, node); } } }
public void OnComplete(BehaviourTreeExecutor <TBlackboard> executor, BehaviourTreeExecutionData <TBlackboard> execution, BehaviourTreeStatus status) { if (status != _status) { executor.Stop(execution, this, BehaviourTreeStatus.Success); } else { executor.Schedule(execution, Node, this); } }
public void Stop(BehaviourTreeExecutionData <TBlackboard> data, BehaviourTreeNode <TBlackboard> node, BehaviourTreeStatus status) { RemoveNode(data, node); data.Statuses[node.Id] = status; if (node.Observer != null) { node.Observer.OnComplete(this, data, status); } }
public void OnComplete(BehaviourTreeExecutor <TBlackboard> executor, BehaviourTreeExecutionData <TBlackboard> execution, BehaviourTreeStatus status) { var node = GetCurrentChild(execution); if (execution.Statuses[node.Id] == BehaviourTreeStatus.Success) { executor.Stop(execution, this, BehaviourTreeStatus.Success); return; } var currentChild = ++execution.Variables[_currentChildId]; if (currentChild == ChildrenCount) { executor.Stop(execution, this, BehaviourTreeStatus.Failure); } else { executor.Start(execution, GetCurrentChild(execution), this); } }
protected override BehaviourTreeStatus Update(BehaviourTreeExecutor <TBlackboard> executor, BehaviourTreeExecutionData <TBlackboard> data, TBlackboard blackboard) { const int undefined = int.MinValue; var tick = _tickSupplier.Supply(); if (data.Variables[_startTickId] == undefined) { data.Variables[_startTickId] = tick; } if (tick - data.Variables[_startTickId] < _ticksToWaitSupplier.Supply(blackboard)) { return(BehaviourTreeStatus.Running); } data.Variables[_startTickId] = undefined; return(BehaviourTreeStatus.Success); }
public void Abort(BehaviourTreeExecutionData <TBlackboard> data, BehaviourTreeNode <TBlackboard> node) { RemoveNode(data, node); node.Abort(data); }
public void Start(BehaviourTreeExecutionData <TBlackboard> data) { Start(data, _root); }
protected override BehaviourTreeStatus Update(BehaviourTreeExecutor <TBlackboard> executor, BehaviourTreeExecutionData <TBlackboard> data, TBlackboard blackboard) { return(BehaviourTreeStatus.Running); }
private BehaviourTreeNode <TBlackboard> GetCurrentChild(BehaviourTreeExecutionData <TBlackboard> data) { return(Children[data.Variables[_currentChildId]]); }
public override void Initialize(BehaviourTreeExecutor <TBlackboard> executor, BehaviourTreeExecutionData <TBlackboard> data, TBlackboard blackboard) { data.Variables[_startTickId] = int.MinValue; }
public override void Initialize(BehaviourTreeExecutor <TBlackboard> executor, BehaviourTreeExecutionData <TBlackboard> data, TBlackboard blackboard) { data.Variables[_currentChildId] = 0; executor.Start(data, GetCurrentChild(data), this); }
public void OnComplete(BehaviourTreeExecutor <TBlackboard> executor, BehaviourTreeExecutionData <TBlackboard> execution, BehaviourTreeStatus status) { executor.Stop(execution, this, BehaviourTreeStatus.Failure); }
public override void Initialize(BehaviourTreeExecutor <TBlackboard> executor, BehaviourTreeExecutionData <TBlackboard> data, TBlackboard blackboard) { executor.Start(data, Node, this); }
public BehaviourTreeData(BehaviourTree <TScope> behaviourTree, BehaviourTreeExecutionData <Entity <TScope> > executionData = null) { BehaviourTree = behaviourTree; ExecutionData = executionData; }
public override void Initialize(BehaviourTreeExecutor <TBlackboard> executor, BehaviourTreeExecutionData <TBlackboard> data, TBlackboard blackboard) { data.Variables[_failedCountId] = 0; data.Variables[_succeededCountId] = 0; foreach (var node in Children) { executor.Start(data, node, this); } }