protected override int onUpdate(TBTWorkingData wData) { TBTActionPrioritizedSelectorContext thisContext = getContext <TBTActionPrioritizedSelectorContext>(wData); int runningState = TBTRunningStatus.FINISHED; // 如果切换节点index了,那么执行转换 // 那么现在就是上次选择节点和当前节点一致了 if (thisContext.currentSelectedIndex != thisContext.lastSelectedIndex) { if (IsIndexValid(thisContext.lastSelectedIndex)) { TBTAction node = GetChild <TBTAction>(thisContext.lastSelectedIndex); node.Transition(wData); } thisContext.lastSelectedIndex = thisContext.currentSelectedIndex; } // 更新当前节点,如果当前节点状态结束,那么设置当前节点为非法 if (IsIndexValid(thisContext.lastSelectedIndex)) { TBTAction node = GetChild <TBTAction>(thisContext.lastSelectedIndex); runningState = node.Update(wData); if (TBTRunningStatus.IsFinished(runningState)) { // 这里应该用Transition thisContext.lastSelectedIndex = -1; } } return(runningState); }
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 int onUpdate(TBTWorkingData wData) { TBTActionTimerContext thisContext = getContext <TBTActionTimerContext>(wData); int runningStatus = TBTRunningStatus.FINISHED; if (IsIndexValid(0)) { TBTAction node = GetChild <TBTAction>(0); runningStatus = node.Update(wData); if (TBTRunningStatus.IsFinished(runningStatus)) { if (UnityEngine.Time.time > thisContext.lastTime + m_elapseTime) { runningStatus = TBTRunningStatus.FINISHED; } } else if (TBTRunningStatus.IsExecuting(runningStatus)) { if (UnityEngine.Time.time > thisContext.lastTime + m_elapseTime) { thisContext.lastTime = UnityEngine.Time.time; } } } return(runningStatus); }
protected sealed override int onUpdate(TBTWorkingData wData) { int runningState = TBTRunningStatus.FINISHED; TBTActionLeafContext thisContext = getContext <TBTActionLeafContext>(wData); if (thisContext.status == ACTION_READY) { onEnter(wData); thisContext.needExit = true; thisContext.status = ACTION_RUNNING; } if (thisContext.status == ACTION_RUNNING) { runningState = onExecute(wData); if (TBTRunningStatus.IsFinished(runningState)) { thisContext.status = ACTION_FINISHED; } } if (thisContext.status == ACTION_FINISHED) { if (thisContext.needExit) { onExit(wData, runningState); } thisContext.status = ACTION_READY; thisContext.needExit = false; } return(runningState); }
protected override int onUpdate(TBTWorkingData wData) { TBTActionPrioritizedSelectorContext thisContext = getContext <TBTActionPrioritizedSelectorContext>(wData); int runningState = TBTRunningStatus.FINISHED; if (thisContext.currentSelectedIndex != thisContext.lastSelectedIndex) { if (IsIndexValid(thisContext.lastSelectedIndex)) { TBTAction node = GetChild <TBTAction>(thisContext.lastSelectedIndex); node.Transition(wData); } thisContext.lastSelectedIndex = thisContext.currentSelectedIndex; } if (IsIndexValid(thisContext.lastSelectedIndex)) { TBTAction node = GetChild <TBTAction>(thisContext.lastSelectedIndex); runningState = node.Update(wData); if (TBTRunningStatus.IsFinished(runningState)) { thisContext.lastSelectedIndex = -1; } } return(runningState); }
protected sealed override int onUpdate(TBTWorkingData wData) { int runningState = TBTRunningStatus.FINISHED; TBTActionLeafContext thisContext = getContext <TBTActionLeafContext>(wData); // 只执行一次 if (thisContext.status == ACTION_READY) { onEnter(wData); thisContext.needExit = true; thisContext.status = ACTION_RUNNING; } // status是ACTION_RUNNING,但是thisContext.status是其他的状态 if (thisContext.status == ACTION_RUNNING) { // TBTRunningStatus是内部的执行状态,status是TBTActionLeaf是的状态 runningState = onExecute(wData); if (TBTRunningStatus.IsFinished(runningState)) { thisContext.status = ACTION_FINISHED; } } if (thisContext.status == ACTION_FINISHED) { if (thisContext.needExit) { onExit(wData, runningState); } // 返回默认状态 thisContext.status = ACTION_READY; thisContext.needExit = false; } return(runningState); }
protected override int onUpdate(TBTWorkingData wData) { TBTActionParallelContext thisContext = getContext <TBTActionParallelContext>(wData); //first time initialization if (thisContext.runningStatus.Count != GetChildCount()) { initListTo <int>(thisContext.runningStatus, TBTRunningStatus.EXECUTING); } bool hasFinished = false; bool hasExecuting = false; for (int i = 0; i < GetChildCount(); ++i) { if (thisContext.evaluationStatus[i] == false) { continue; } if (TBTRunningStatus.IsFinished(thisContext.runningStatus[i])) { hasFinished = true; continue; } TBTAction node = GetChild <TBTAction>(i); int runningStatus = node.Update(wData); if (TBTRunningStatus.IsFinished(runningStatus)) { hasFinished = true; } else { hasExecuting = true; } thisContext.runningStatus[i] = runningStatus; } if (_runningStatusRelationship == ECHILDREN_RELATIONSHIP.OR && hasFinished || _runningStatusRelationship == ECHILDREN_RELATIONSHIP.AND && hasExecuting == false) { initListTo <int>(thisContext.runningStatus, TBTRunningStatus.EXECUTING); return(TBTRunningStatus.FINISHED); } return(TBTRunningStatus.EXECUTING); }
protected override int onUpdate(TBTWorkingData wData) { TBTActionLoopContext thisContext = getContext <TBTActionLoopContext>(wData); int runningStatus = TBTRunningStatus.FINISHED; if (IsIndexValid(0)) { TBTAction node = GetChild <TBTAction>(0); runningStatus = node.Update(wData); if (TBTRunningStatus.IsFinished(runningStatus)) { thisContext.currentCount++; if (thisContext.currentCount < _loopCount || _loopCount == INFINITY) { runningStatus = TBTRunningStatus.EXECUTING; } } } return(runningStatus); }