/// <summary> /// Add an action to the end of the queue. /// </summary> /// <param name="action">The action to add to the end of the queue.</param> public void AddAction(ActorAction action) { if (action != null) { this.actions.AddLast(action); } }
public void AddToFront(ActorAction action) { if (action != null) { if (this.actions.First != null) { this.actions.First.Value.enabled = false; } this.actions.AddFirst(action); this.actions.First.Value.enabled = true; } }
/// <summary> /// Removes all currently queued actions from the queue, and replaces them with a new action. /// </summary> /// <param name="action">The action to perform immediately, cancelling all other actions.</param> public void SetAction(ActorAction action) { foreach (ActorAction queuedAction in actions) { Destroy(queuedAction); } actions.Clear(); actions.AddLast(action); if (actions.Count > 0) { actions.First.Value.enabled = true; } }
void Update() { if (actions.Count > 0) { if (actions.First.Value.Complete == true) { ActorAction action = actions.First.Value; actions.RemoveFirst(); Destroy(action); // Enable the next action in the queue if (actions.Count > 0) { actions.First.Value.enabled = true; } } } }