Example #1
0
        // Command field input is changed, check if command is submitted
        public char OnValidateCommand(string text, int charIndex, char addedChar)
        {
            // If command is submitted
            if (addedChar == '\n')
            {
                // Clear the command field
                if (clearCommandAfterExecution)
                {
                    commandInputField.text = "";
                }

                if (text.Length > 0)
                {
                    // Execute the command
                    DebugLogConsole.ExecuteCommand(text);

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

                return('\0');
            }

            return(addedChar);
        }
        public void DoCommand()
        {
            string text = commandInputField.text;

            // Clear the command field
            if (clearCommandAfterExecution)
            {
                commandInputField.text = "";
            }

            if (text.Length > 0)
            {
                // Execute the command
                try
                {
                    DebugLogConsole.ExecuteCommand(text);
                }
                catch (Exception e)
                {
                    UnityEngine.Debug.LogException(e);
                }
                finally
                {
                    // Snap to bottom and select the latest entry
                    SetSnapToBottom(true);
                    RectTransform inputRT = commandInputField.GetComponent <RectTransform>();
                    Vector2       size    = inputRT.sizeDelta;
                    size.y            = 36;
                    inputRT.sizeDelta = size;
                }
            }
        }
Example #3
0
        // Command field input is changed, check if command is submitted
        public char OnValidateCommand(string text, int charIndex, char addedChar)
        {
            // If command is submitted
            if (addedChar == '\n')
            {
                // Clear the command field
                if (clearCommandAfterExecution)
                {
                    commandInputField.text = "";
                }

                if (text.Length > 0)
                {
                    // Execute the command
                    DebugLogConsole.ExecuteCommand(text);

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

                    if (indicesOfListEntriesToShow.Count > 0)
                    {
                        OnLogClicked(indicesOfListEntriesToShow.Count - 1);
                    }
                }

                return('\0');
            }

            return(addedChar);
        }
        // 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);
        }
Example #5
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);
        }
Example #6
0
 public void Init(ConsoleMethodInfo consoleMethodInfo)
 {
     Input.placeholder.GetComponent <Text>().text = "请输入参数,类型在上面,每个参数用空格分隔";
     Input.gameObject.SetActive(consoleMethodInfo.parameterTypes.Length > 0);
     oldName      = $">{consoleMethodInfo.command}({string.Join("",consoleMethodInfo.parameters)})";
     NameTxt.text = oldName;
     DescTxt.text = consoleMethodInfo.description;
     Btn.onClick.AddListener(() =>
     {
         DebugLogConsole.ExecuteCommand($"{consoleMethodInfo.command} {Input.text}");
         btnImg.color = Color.green;
         NameTxt.text = "执行成功!!";
         StartCoroutine(Delay(1, () =>
         {
             btnImg.color = Color.white;
             NameTxt.text = oldName;
         }));
     });
 }
Example #7
0
        // Click the submit btn
        public void SubmitInputCommand()
        {
            var text = commandInputField.text;

            // Clear the command field
            if (clearCommandAfterExecution)
            {
                commandInputField.text = "";
            }

            if (text.Length > 0)
            {
                // Execute the command
                DebugLogConsole.ExecuteCommand(text);

                // Snap to bottom and select the latest entry
                SetSnapToBottom(true);
            }
        }
Example #8
0
        public void SendCommandButtonPressed()
        {
            if (clearCommandAfterExecution)
            {
                commandInputField.text = "";
            }

            if (commandInputField.text.Length > 0)
            {
                // Execute the command
                DebugLogConsole.ExecuteCommand(commandInputField.text);

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

                if (indicesOfListEntriesToShow.Count > 0)
                {
                    OnLogClicked(indicesOfListEntriesToShow.Count - 1);
                }
            }
        }