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 void OnTransition(BtWorkingData workData) { BtActionPrioritizedSelectorContext thisContext = GetContext <BtActionPrioritizedSelectorContext>(workData); BtAction node = GetChild <BtAction>(thisContext._lastSelectedIndex); if (node != null) { node.Transition(workData); } thisContext._lastSelectedIndex = -1; }
protected override bool OnEvaluate(BtWorkingData workData) { BtActionPrioritizedSelectorContext thisContext = GetContext <BtActionPrioritizedSelectorContext>(workData); //check last node first if (IsIndexValid(thisContext._currentSelectedIndex)) { BtAction node = GetChild <BtAction>(thisContext._currentSelectedIndex); if (node.Evaluate(workData)) { return(true); } } return(base.OnEvaluate(workData)); }
protected override bool OnEvaluate(BtWorkingData workData) { BtActionPrioritizedSelectorContext thisContext = GetContext <BtActionPrioritizedSelectorContext>(workData); thisContext._currentSelectedIndex = -1; int childCount = GetChildCount(); for (int i = 0; i < childCount; i++) { BtAction node = GetChild <BtAction>(i); if (node.Evaluate(workData)) { thisContext._currentSelectedIndex = i; return(true); } } return(false); }