protected override int OnUpdate(BtWorkingData workData) { BtActionSequenceContext thisContext = GetContext <BtActionSequenceContext>(workData); int runningStatus = BtRunningStatus.FINISHED; BtAction node = GetChild <BtAction>(thisContext.current_selected_index); runningStatus = node.Update(workData); if (_continueIfErrorOccors == false && BtRunningStatus.IsError(runningStatus)) { thisContext.current_selected_index = -1; return(runningStatus); } if (BtRunningStatus.IsFinished(runningStatus)) { thisContext.current_selected_index++; if (IsIndexValid(thisContext.current_selected_index)) { runningStatus = BtRunningStatus.EXECUTING; } else { thisContext.current_selected_index = -1; } } return(runningStatus); }
protected override int OnUpdate(BtWorkingData workData) { BtActionPrioritizedSelectorContext thisContext = GetContext <BtActionPrioritizedSelectorContext>(workData); int runningState = BtRunningStatus.FINISHED; if (thisContext._currentSelectedIndex != thisContext._lastSelectedIndex) { if (IsIndexValid(thisContext._lastSelectedIndex)) { BtAction node = GetChild <BtAction>(thisContext._lastSelectedIndex); node.Transition(workData); } thisContext._lastSelectedIndex = thisContext._currentSelectedIndex; } if (IsIndexValid(thisContext._lastSelectedIndex)) { BtAction node = GetChild <BtAction>(thisContext._lastSelectedIndex); runningState = node.Update(workData); if (BtRunningStatus.IsFinished(runningState)) { thisContext._lastSelectedIndex = -1; } } return(runningState); }
protected override int OnUpdate(BtWorkingData workData) { BtActionParallelContext thisContext = GetContext <BtActionParallelContext>(workData); //first time initialization if (thisContext._runningStatus.Count != GetChildCount()) { _init_list_to(thisContext._runningStatus, BtRunningStatus.EXECUTING); } bool hasFinished = false; bool hasExecuting = false; for (int i = 0; i < GetChildCount(); ++i) { if (thisContext._evaluationStatus[i] == false) { continue; } if (BtRunningStatus.IsFinished(thisContext._runningStatus[i])) { hasFinished = true; continue; } BtAction node = GetChild <BtAction>(i); int runningStatus = node.Update(workData); if (BtRunningStatus.IsFinished(runningStatus)) { hasFinished = true; } else { hasExecuting = true; } thisContext._runningStatus[i] = runningStatus; } if (_runningstatusRelationship == E_ChildrenRelationShip.or && hasFinished || _runningstatusRelationship == E_ChildrenRelationShip.and && hasExecuting == false) { _init_list_to(thisContext._runningStatus, BtRunningStatus.EXECUTING); return(BtRunningStatus.FINISHED); } return(BtRunningStatus.EXECUTING); }
protected override int OnUpdate(BtWorkingData workData) { int runningState = BtRunningStatus.FINISHED; BtActionLeafContext leafContext = GetContext <BtActionLeafContext>(workData); int currStatus = leafContext._status; if (currStatus == ACTION_READY) { OnEnter(workData); leafContext.OnEnter(); } if (currStatus == ACTION_RUNNING) { runningState = OnExecute(workData); if (BtRunningStatus.IsFinished(runningState)) { leafContext.OnFinish(); } } if (currStatus == ACTION_FINISHED) { if (leafContext._needExit) { OnExit(workData, runningState); } else { LogManager.Error("节点退出错误,[{0}]", TbName); } leafContext.OnExit(); } return(runningState); }