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; } // } } }
public void Start() { foreach (GoalEntry ge in Goals) { GAgentSubGoal subGoal = new GAgentSubGoal(); subGoal.SubGoals = new Dictionary <GKey, int>(); foreach (WorldState gs in ge.States) { subGoal.SubGoals.Add(gs.Key, gs.Value); } subGoal.Remove = ge.Remove; mGoals.Add(subGoal, ge.Priority); } GAction[] acts = this.GetComponents <GAction>(); foreach (GAction a in acts) { mActions.Add(a); } }