protected override int onUpdate(TBTWorkingData wData) { TBTActionSequenceContext thisContext = getContext <TBTActionSequenceContext>(wData); int runningStatus = TBTRunningStatus.FINISHED; TBTAction node = GetChild <TBTAction>(thisContext.currentSelectedIndex); // 更新当前节点 runningStatus = node.Update(wData); // 如果当前节点结束或者失败,那么父节点也结束 if (_continueIfErrorOccors == false && TBTRunningStatus.IsError(runningStatus)) { thisContext.currentSelectedIndex = -1; return(runningStatus); } // 如果当前节点结束,那么切换下一个节点 if (TBTRunningStatus.IsFinished(runningStatus)) { thisContext.currentSelectedIndex++; // 这个检测不应该放在这里 if (IsIndexValid(thisContext.currentSelectedIndex)) { runningStatus = TBTRunningStatus.EXECUTING; } else { thisContext.currentSelectedIndex = -1; } } return(runningStatus); }
//------------------------------------------------------ protected override bool onEvaluate(/*in*/ TBTWorkingData wData) { TBTActionSequenceContext thisContext = getContext <TBTActionSequenceContext>(wData); int checkedNodeIndex = -1; if (IsIndexValid(thisContext.currentSelectedIndex)) { checkedNodeIndex = thisContext.currentSelectedIndex; } else { checkedNodeIndex = 0; } // 检测当前节点 if (IsIndexValid(checkedNodeIndex)) { TBTAction node = GetChild <TBTAction>(checkedNodeIndex); if (node.Evaluate(wData)) { thisContext.currentSelectedIndex = checkedNodeIndex; return(true); } } return(false); }
protected override int onUpdate(TBTWorkingData wData) { TBTActionSequenceContext thisContext = getContext <TBTActionSequenceContext>(wData); int runningStatus = TBTRunningStatus.FINISHED; if (IsIndexValid(thisContext.currentSelectedIndex)) { TBTAction node = GetChild <TBTAction>(thisContext.currentSelectedIndex); runningStatus = node.Update(wData); if (_continueIfErrorOccurs == false && TBTRunningStatus.IsError(runningStatus)) { thisContext.currentSelectedIndex = -1; return(runningStatus); } } if (TBTRunningStatus.IsFinished(runningStatus)) { thisContext.currentSelectedIndex++; if (IsIndexValid(thisContext.currentSelectedIndex)) { runningStatus = TBTRunningStatus.EXECUTING; } else { thisContext.currentSelectedIndex = -1; } } return(runningStatus); }
protected override void onTransition(TBTWorkingData wData) { TBTActionSequenceContext thisContext = getContext <TBTActionSequenceContext>(wData); TBTAction node = GetChild <TBTAction>(thisContext.currentSelectedIndex); if (node != null) { node.Transition(wData); } }
protected override void onTransition(BehaviourTreeData wData) { TBTActionSequenceContext thisContext = getContext <TBTActionSequenceContext>(wData); BehaviourAction node = GetChild <BehaviourAction>(thisContext.currentSelectedIndex); if (node != null) { node.Transition(wData); } thisContext.currentSelectedIndex = -1; }
protected override bool onEvaluate(TBTWorkingData wData) { TBTActionSequenceContext thisContext = getContext <TBTActionSequenceContext>(wData); int checkNodeIndex = IsIndexValid(thisContext.currentSelectedIndex) ? thisContext.currentSelectedIndex : 0; if (IsIndexValid(checkNodeIndex)) { TBTAction node = GetChild <TBTAction>(checkNodeIndex); if (node.Evaluate(wData)) { thisContext.currentSelectedIndex = checkNodeIndex; return(true); } } return(false); }