public void ContemplateOptions() { CommandExecuter.ParseCommand(currentCommand, out string commandName, out string[] args); options.Clear(); ICommand command = CommandExecuter.FindCommand(x => x != null && x.Name == commandName); if (command != null && (args.Length > 0 || currentCommand.EndsWith(" "))) { currentArg = Mathf.Max(0, args.Length - 1); string currentText = ""; if (currentArg < args.Length) { currentText = args[currentArg]; } if (currentCommand.EndsWith(" ") && args.Length > 0) { currentArg += 1; currentText = ""; } if (!cachedSuggestions.TryGetValue(currentArg, out List <string> suggestions)) { suggestions = command.GetSuggestions(currentArg); cachedSuggestions.Add(currentArg, suggestions); } else { suggestions = cachedSuggestions[currentArg]; } foreach (string s in suggestions) { if (s.Contains(currentText) || currentText == "") { options.Add(new AutocompleteOption(s)); } } } else { currentArg = -1; cachedSuggestions.Clear(); // Show commands autocomplete foreach (var c in CommandExecuter.CommandListReadOnly) { if (c != null && c.Name.Contains(commandName)) { StringBuilder additional = new StringBuilder(c.Name); foreach (var arg in c.ParamInfo) { if (arg == null) { additional.Append(" unknown"); } else { additional.Append(" ").Append(arg.ParameterName); } } var o = new AutocompleteOption(c.Name, additional.ToString()); options.Add(o); } } } selectionInDropDown = -1; selectionInHistory = -1; showDropDown = true; }