Пример #1
0
        public void ShowAutoCompletionTips(string typedInput)
        {
            typedInputString = typedInput;

            ClearTemplates();

            List <ConObject> matchingConObjects = SourceConsole.GetAllConObjectsThatMatch(typedInputString);

            matchingConObjectsCount = matchingConObjects.Count;
            if (matchingConObjects.Count > 0)
            {
                for (int i = verticalScrollIndex; i < Mathf.Min(matchingConObjects.Count, verticalScrollIndex + showMaxAutocompletes); i++)
                {
                    var command = matchingConObjects[i];

                    if (command is ConCommand)
                    {
                        AddTemplate((ConCommand)command);
                    }
                    else
                    {
                        AddTemplate((ConVar)command);
                    }
                }

                Show();
                UpdateSelectedAutoComplete();
            }
            else
            {
                Hide();
            }
        }
 private void OnClick()
 {
     SourceConsole.ExecuteString(command);
 }
        private void Start()
        {
            SourceConsole.RefreshCommands();

            Hide();
        }
        public void CommandEntered(string input)
        {
            if (input == "")
            {
                return;
            }
            if (!Input.GetKeyDown(KeyCode.Return) && !Input.GetKeyDown(KeyCode.KeypadEnter))
            {
                return;
            }

            //reset text and select console input
            consoleInput.text = "";
            consoleInput.OnSelect(null);
            ResetCommandHistoryIndex();

            string[] parts       = input.Split(' '); //split the input string into parts
            string   commandName = parts[0];         //get just the command name

            //insert command history (regardless of if the command is valid or not)
            if (commandsHistory.Count == 0) //if no command history. add anyways
            {
                commandsHistory.Add(input);
            }
            else
            {
                if (commandsHistory[commandsHistory.Count - 1] != input)
                {
                    commandsHistory.Add(input);                                                      //add only if last command isnt identical
                }
            }
            if (commandsHistory.Count > 6)
            {
                commandsHistory.RemoveAt(0);                             //make sure history list is not too big
            }
            var command = SourceConsole.GetConObjectByName(commandName); //get either the convar or concommand typed

            if (command != null)                                         //if the command exists
            {
                string[] cleanParts = SourceConsoleHelper.CleanArgumentsArray(parts, command.GetParametersLength());

                SourceConsole.print($"<color=#ffffffaa>{input}</color>");

                if (command is ConCommand)
                {
                    //If you want to display the return value of the function...
                    if (ShowMethodReturns)
                    {
                        object commandResult = SourceConsole.ExecuteCommand((ConCommand)command, SourceConsoleHelper.CastParameters(cleanParts));
                        if (commandResult != null)
                        {
                            print($"commandName = {commandResult}");
                        }
                    }
                    else
                    {
                        SourceConsole.ExecuteCommand((ConCommand)command, SourceConsoleHelper.CastParameters(cleanParts));
                    }
                }
                else //if no command, then convar
                {
                    object result = SourceConsole.ExecuteConvar((ConVar)command, SourceConsoleHelper.CastParameters(cleanParts));
                    if (result != null)
                    {
                        if (command.GetDescription() == "")
                        {
                            SourceConsole.print($"<color=#ffffffaa>{commandName} = {result}</color>");
                        }
                        else
                        {
                            SourceConsole.print($"<color=#ffffffaa>{commandName} = {result}\n\"{command.GetDescription()}\"</color>");
                        }
                    }
                }
            }
            else
            {
                SourceConsole.print($"Command '{commandName}' does not exist!");
            }
        }