Esempio n. 1
0
        // Attempts to complete what's already been typed if it matches an existing command
        protected void autoCompleteCommand()
        {
            var input = _commandInputField.text.Trim();

            if (string.IsNullOrEmpty(input))
            {
                return;
            }

            var commands = ConsoleCommands.GetOrderedCommands().Where(c => c.Name.StartsWith(input, StringComparison.CurrentCultureIgnoreCase)).ToList();

            if (commands.Count == 1)
            {
                _commandInputField.text = commands[0].Name;
                _commandInputField.MoveTextEnd(false);
            }
            // If there's more than one available, list them in a single log
            else if (commands.Count > 1)
            {
                var output = new StringBuilder();

                for (var i = 0; i < commands.Count; i++)
                {
                    output.Append(commands[i].Name);

                    if (i != commands.Count - 1)
                    {
                        output.Append("\t\t");
                    }
                }

                Console.Log(output.ToString());
            }
        }
Esempio n. 2
0
        // Parse the command
        private static void parseCommand(string command)
        {
            _instance._consoleHistory.AddCommandToHistory(command);

            var commandSplit = parseArguments(command.Trim());
            var commandName  = commandSplit[0];

            commandSplit.RemoveAt(0);

            // Show the command we executed
            var tempLog = new ConsoleLog($"> { command }", string.Empty, LogType.Log);

            _instance._consoleHistory.AddLogToHistory(tempLog);

            ConsoleCommands.ExecuteCommand(commandName, commandSplit.ToArray());
        }
Esempio n. 3
0
        // Apply singleton
        private void Awake()
        {
            if (_instance == null)
            {
                _instance = this;
            }
            else
            {
                Debug.Log("There's already an instance of CC.Console");
                Destroy(gameObject);
            }

            _consoleHistory = new ConsoleHistory(_config.LogHistoryCapacity, _config.CommandHistoryCapacity);
            ConsoleCommands.AddDefaultCommands();

            if (_config.DontDestroyOnLoad)
            {
                DontDestroyOnLoad(gameObject);
            }

            instantiateView();
        }