// Command field input is changed, check if command is submitted
        public char OnValidateCommand(string text, int charIndex, char addedChar)
        {
            if (addedChar == '\t')              // Autocomplete attempt
            {
                text = text.TrimStart();
                if (!string.IsNullOrEmpty(text))
                {
                    DebugLogConsole.AutoCompleteResults results = DebugLogConsole.GetAutoComplete(text);
                    if (results.error == null)
                    {
                        if (results.replacement != null)
                        {
                            commandInputField.text = results.replacement;
                        }
                        if (results.options.Count > 1)
                        {
                            Debug.Log("Options: " + String.Join(", ", results.options));
                        }
                    }
                    else
                    {
                        Debug.LogWarning(results.error);
                    }
                }

                return('\0');
            }
            else if (addedChar == '\n')              // Command is submitted
            {
                // Clear the command field
                if (clearCommandAfterExecution)
                {
                    commandInputField.text = "";
                }

                if (text.Length > 0)
                {
                    if (commandHistory.Count == 0 || commandHistory[commandHistory.Count - 1] != text)
                    {
                        commandHistory.Add(text);
                    }

                    commandHistoryIndex = -1;

                    // Execute the command
                    DebugLogConsole.ExecuteCommand(text);

                    // Snap to bottom and select the latest entry
                    SetSnapToBottom(true);
                }

                return('\0');
            }

            return(addedChar);
        }
Exemple #2
0
        // Command field input is changed, check if command is submitted
        public char OnValidateCommand(string text, int charIndex, char addedChar)
        {
            if (addedChar == '\t') // Autocomplete attempt
            {
                if (!string.IsNullOrEmpty(text))
                {
                    string autoCompletedCommand = DebugLogConsole.GetAutoCompleteCommand(text);
                    if (!string.IsNullOrEmpty(autoCompletedCommand))
                    {
                        commandInputField.text = autoCompletedCommand;
                    }
                }

                return('\0');
            }
            else if (addedChar == '\n') // Command is submitted
            {
                // Clear the command field
                if (clearCommandAfterExecution)
                {
                    commandInputField.text = "";
                }

                if (text.Length > 0)
                {
                    if (commandHistory.Count == 0 || commandHistory[commandHistory.Count - 1] != text)
                    {
                        commandHistory.Add(text);
                    }

                    commandHistoryIndex = -1;

                    // Execute the command
                    DebugLogConsole.ExecuteCommand(text);

                    // Snap to bottom and select the latest entry
                    SetSnapToBottom(true);
                }

                return('\0');
            }

            return(addedChar);
        }