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); }
public int UpdateBehavior(float game_time, float delta_time) { if (_current_request == null) { return(0); } //update working data //_behavior_working_data.EntityAnimator.speed = GameTimer.Instance.timeScale; _behavior_working_data.GameTime = game_time; _behavior_working_data.DeltaTime = delta_time; //test bb usage _blackboard.SetValue(BBKEY_NEXTMOVINGPOSITION, _current_request.NextMovingTarget); if (_behavior_tree.Evaluate(_behavior_working_data)) { _behavior_tree.Update(_behavior_working_data); } else { _behavior_tree.Transition(_behavior_working_data); } return(0); }