private void OnGUI() { if (!_showConsole) { return; } if (_showHelp) { GUI.Box(new Rect(_topLeftOffset.x, _topLeftOffset.y, Screen.width, 100), string.Empty); Rect viewport = new Rect(0, 0, Screen.width - 30, 20 * commandList.Count); _scroll = GUI.BeginScrollView(new Rect(_topLeftOffset.x, _topLeftOffset.y + 5f, Screen.width, 90), _scroll, viewport); for (int i = 0; i < commandList.Count; i++) { TerminalCommandBase command = commandList[i] as TerminalCommandBase; string label = $"{command.Command.Format} - {command.Command.Description}"; Rect labelRect = new Rect(5, 20 * i, viewport.width - 100, 20); GUI.Label(labelRect, label); } GUI.EndScrollView(); } GUI.Box(new Rect(_topLeftOffset.x, _topLeftOffset.y + 100f, Screen.width, 30), string.Empty); GUI.backgroundColor = new Color(0, 0, 0, 0); // Set the internal name of the textfield to get focus GUI.SetNextControlName("InputText"); _input = GUI.TextField(new Rect(_topLeftOffset.x + 10f, _topLeftOffset.y + 100f + 5f, Screen.width - 20f, 20f), _input); GUI.FocusControl("InputText"); }
private void HandleInput() { if (string.IsNullOrEmpty(_input)) { Debug.Log("No input to process"); return; } string[] properties = _input.Split(' '); // maybe use a dict? for (int i = 0; i < commandList.Count; i++) { var command = commandList[i]; TerminalCommandBase commandBase = command as TerminalCommandBase; if (_input.Contains(commandBase.Command.Id)) { switch (command) { case TerminalCommand terminalCommand: terminalCommand?.Invoke(); break; case TerminalCommand <int> terminalCommand: if (int.TryParse(properties[i], out var intParsed)) { terminalCommand?.Invoke(intParsed); } else { Debug.Log("[DebugController] Syntax error! Expected integer value"); } break; case TerminalCommand <bool> terminalCommand: if (bool.TryParse(properties[i], out var boolParsed)) { terminalCommand?.Invoke(boolParsed); } else { Debug.Log("[DebugController] Syntax error! Expected bool value"); } break; } } } }