/// <summary> /// Run every tick, while node this node in Running State /// </summary> /// <param name="blackboard">Blackboard object</param> protected internal abstract void Tick(TBlackboard blackboard, NodeContext <TBlackboard> nodeContext);
/// <summary> /// Run on node complete (immediately after Run method returs False ) /// </summary> /// <param name="blackboard">Blackboard object</param> /// <returns>True in case of Ok status, false in case of Fail</returns> protected internal virtual bool Complete(TBlackboard blackboard, NodeContext <TBlackboard> nodeContext) { return(true); }
/// <summary> /// Run on node start /// </summary> /// <param name="blackboard">Blackboard object</param> /// <returns>True if success and node moves to Status.Running state, False in case of Fail</returns> protected internal abstract bool Start(TBlackboard blackboard, NodeContext <TBlackboard> nodeContext);
/// <summary> /// Check if action is complete /// </summary> /// <param name="blackboard">Balckboard object</param> /// <returns>True if node is still in Status.Running state, False - node execution is complete</returns> protected internal abstract bool IsInProgress(TBlackboard blackboard, NodeContext <TBlackboard> nodeContext);
protected internal override bool Complete(TBlackboard blackboard, NodeContext <TBlackboard> nodeContext) { return(Childs.All(x => x.Complete(blackboard, nodeContext))); }
protected override CompositeStatus UpdateChilds(Context <TBlackboard> context, NodeContext <TBlackboard> nodeContext) { CompositeStatus result = new CompositeStatus() { Status = Status.Ok }; int startIndex = 0; //if node contains running childs, update it firstly if (nodeContext.IsRunning) { int index = nodeContext.ChildNodeIndex; Node <TBlackboard> node = Childs[index]; result.Status = node.Update(context); result.ChidlNodeIndex = index; startIndex = index + 1; } //if previous node was successful if (result.Status == Status.Ok) { for (int i = startIndex; i < Childs.Length; i++) { Node <TBlackboard> node = Childs[i]; if (node == null) { throw new NullReferenceException("BTNode child can not be null"); } result.Status = node.Update(context); //stop if node Fails or in running state if (result.Status == Status.Fail || result.Status == Status.Running) { result.ChidlNodeIndex = i; break; } } } return(result); }
protected internal override bool Start(TBlackboard blackboard, NodeContext <TBlackboard> nodeContext) { return(Childs.All(x => x.Start(blackboard, nodeContext))); }
protected override CompositeStatus UpdateChilds(Context <TBlackboard> context, NodeContext <TBlackboard> nodeContext) { CompositeStatus result = new CompositeStatus() { Status = Status.Fail }; for (int i = 0; i < Childs.Length; i++) { Node <TBlackboard> node = Childs[i]; if (node == null) { throw new NullReferenceException("BTNode child can not be null"); } //check if this child is running in previous update bool isRunning = nodeContext.IsRunning && (i == nodeContext.ChildNodeIndex); //update child result.Status = node.Update(context); //stop if Succeed if (result.Status == Status.Ok || result.Status == Status.Running) { result.ChidlNodeIndex = i; break; } } return(result); }
protected internal override bool Complete(TBlackboard blackboard, NodeContext <TBlackboard> nodeContext) { return(true); }
/// <summary> /// Evaluate state of composite node based on their child nodes /// </summary> /// <param name="context">BT Context</param> /// <param name="runningNodeIndex">Index of child node, which currantly in running state, null if node does not have such child node</param> /// <returns></returns> protected abstract CompositeStatus UpdateChilds(Context <TBlackboard> context, NodeContext <TBlackboard> nodeContext);
protected internal override bool IsInProgress(TBlackboard blackboard, NodeContext <TBlackboard> nodeContext) { return(true); }
/// <summary> /// Save currently visiting node /// </summary> /// <param name="node">visiting node</param> internal NodeContext <TBlackboard> PushVisitingNode(Node <TBlackboard> node) { NodeContext <TBlackboard> result = _currentPath.Push(node, _lastRunningPath); return(result); }
/// <summary> /// Run on update this node /// </summary> /// <param name="context">Context for BT current update</param> /// <param name="nodeContext">node context</param> /// <returns></returns> protected abstract Status OnUpdate(Context <TBlackboard> context, NodeContext <TBlackboard> nodeContext);
public void Release(NodeContext <T> nodeContext) { //nothing }
protected internal override bool IsInProgress(TBlackboard blackboard, NodeContext <TBlackboard> nodeContext) { return(Childs.All(x => x.IsInProgress(blackboard, nodeContext))); }
public void Release(NodeContext <T> nodeContext) { _freeObjects.Push(nodeContext); }
private void Add(NodeContext <TBlackboard> nodeContext) { _nodesContext.Add(nodeContext); }