void LateUpdate() { if (mCurrentAction != null && mCurrentAction.Running) { mCurrentAction.Perform(); if (!mCurrentAction.Running) { mCurrentAction.PostPerform(); mCurrentAction = null; } else { return; } } if (mPlanner == null || mActionQueue == null) { mPlanner = new GPlanner(); var sortedGoals = from entry in mGoals orderby entry.Value descending select entry; foreach (KeyValuePair <GAgentSubGoal, int> sg in sortedGoals) { mActionQueue = mPlanner.Plan(mActions, sg.Key.SubGoals, Beliefs); if (mActionQueue != null) { mCurrentGoal = sg.Key; break; } } } if (mActionQueue != null && mActionQueue.Count == 0) { if (mCurrentGoal.Remove) { mGoals.Remove(mCurrentGoal); } mPlanner = null; } if (mActionQueue != null && mActionQueue.Count > 0) { GAction newAction = mActionQueue.Dequeue(); //if (newAction != currentAction) // { mCurrentAction = newAction; if (!mCurrentAction.PrePerform()) { mActionQueue = null; } // } } }
private void CreatePerformActionState() { performActionState = (fsm, gagent) => { if (!HasActionPlan()) { Debug.Log("Done with actions, planning new actions."); fsm.PopState(); fsm.PushState(planningState); worldDataProvider.ActionsFinished(); return; } GAction action = currentActions.Peek(); if (action.IsDone()) { currentActions.Dequeue(); } if (HasActionPlan()) { action = currentActions.Peek(); bool success = action.Perform(gagent); if (!success) { fsm.PopState(); fsm.PushState(planningState); worldDataProvider.PlanAborted(action); } } else { fsm.PopState(); fsm.PushState(planningState); worldDataProvider.ActionsFinished(); } }; }