private void _add(string[] commands, int command_index, CommandAttribute cmd) { if (commands.Length == command_index) { m_command = cmd; return; } string token = commands[command_index]; if (!m_subcommands.ContainsKey(token)){ m_subcommands[token] = new CommandTree(); } m_subcommands[token]._add(commands, command_index + 1, cmd); }
public void Add(CommandAttribute cmd) { _add(cmd.m_command.ToLower().Split(' '), 0, cmd); }
/* Queue a command to be executed on update on the main thread */ public static void Queue(CommandAttribute command, string[] args) { QueuedCommand queuedCommand = new QueuedCommand(); queuedCommand.command = command; queuedCommand.args = args; Instance.m_commandQueue.Enqueue( queuedCommand ); }
/* Register a new console command */ public static void RegisterCommand(string command, string desc, CommandAttribute.Callback callback, bool runOnMainThread = true) { if (command == null || command.Length == 0) { throw new Exception("Command String cannot be empty"); } CommandAttribute cmd = new CommandAttribute(command, desc, runOnMainThread); cmd.m_callback = callback; Instance.m_commands.Add(cmd); Instance.m_help += string.Format("\n{0} : {1}", command, desc); }