/// <summary> /// Executes the GameCommand and adds it to the list of commands to update. If the GameCommand has UsePriority set to true, it will only be executed if the current priority command is null /// or has a lower priority. /// </summary> public void ExecuteCommand(GameCommand cmd) { if (cmd == null) { return; } if (cmd.State == CommandState.Running) { Debug.LogWarning("Cannot execute a running command"); return; } if (cmd.UsePriority) //Validate execution { if (_current == null || _current.State != CommandState.Running) //No current running command, run this command { _current = cmd; cmd.Execute(); } else if (cmd.Priority > _current.Priority) //Current command has lower priority. Abort current command, run this command { _current.Abort(); _current = cmd; cmd.Execute(); } else//Current command has higher priority, abort this command { cmd.Abort(); } return; } //No priority validation, execute this command _concurrentCommands.Add(cmd); cmd.Execute(); }