public void UpdateAction() { // If there is a current action, update it if (CurrentAction) { CurrentAction.UpdateAction(this); // If the current action has completed, move on to the next action in the queue if (CurrentAction.HasActionCompleted(this)) { CurrentAction.ExitAction(this); // Get the next action from the queue if there is one if (ActionQueue.Count > 0) { CurrentAction = ActionQueue[0]; CurrentAction.EnterAction(this); CurrentAction.ExecuteAction(this); ActionQueue.RemoveAt(0); } else { CurrentAction = null; } RefreshActionRefs(); } } }
/// <summary> /// This will take an action and either set the current action or add it to the queue /// </summary> /// <param name="action">Action to add</param> /// <param name="addToList">If set to false, will set the current action. Otherwise will add to queue</param> public void SetAction(AIAction action, bool addToList, bool checkInList = true) { if (!action) { return; } if (CurrentAction && CurrentAction.Equals(action) && checkInList) { return; } // If there is no current action or queued action, then just et the current action if (!CurrentAction && ActionQueue.Count == 0) { CurrentAction = action; addToList = false; } // Else if there is a current action, or a queued action, add to the queue else if (addToList) { ActionQueue.Add(action); } // Otherwise, reset the queue and set the current action else { // Exit out of current action if there is one if (CurrentAction) { CurrentAction.ExitAction(this); } // Cancel queued actions Helper.LoopList_ForEach <AIAction>(ActionQueue, (AIAction a) => { a.CancelAction(this); }); ActionQueue.Clear(); CurrentAction = action; } // Enter and execute the new current action, if there is one if (!addToList && CurrentAction) { CurrentAction.EnterAction(this); CurrentAction.ExecuteAction(this); } RefreshActionRefs(); }