private void OnGUI() { if (!showConsole) { return; } float y = 0; if (showHelp) { GUI.Box(new Rect(0, y, Screen.width, 100), ""); Rect viewport = new Rect(0, 0, Screen.width - 30, 20 * commandList.Count); scroll = GUI.BeginScrollView(new Rect(0, y + 5f, Screen.width, 90), scroll, viewport); for (int i = 0; i < commandList.Count; i++) { DebugCommandBase command = commandList[i] as DebugCommandBase; string label = $"{command.CommandFormat} - {command.CommandDescription}"; Rect labelRect = new Rect(5, 20 * i, viewport.width - 100, 20); GUI.Label(labelRect, label); } GUI.EndScrollView(); y += 100; } GUI.Box(new Rect(0, y, Screen.width, 30), ""); GUI.backgroundColor = new Color(0, 0, 0, 0); input = GUI.TextField(new Rect(10f, y + 5f, Screen.width - 20f, 20f), input); }
private void OnGUI() { if (!showConsole) { return; } if (showHelp) { GUI.Box(new Rect(0, Screen.height - 130f, Screen.width, 100), ""); Rect viewport = new Rect(0, Screen.height - 130f, Screen.width - 130f, 20 * commandList.Count); scroll = GUI.BeginScrollView(new Rect(0, Screen.height - 135f, Screen.width, 90), scroll, viewport); for (int i = 0; i < commandList.Count; i++) { DebugCommandBase command = commandList[i] as DebugCommandBase; string label = $"{command.commandFormat} - {command.commandDesc}"; Rect labelRect = new Rect(5, Screen.height - 130f + i * 20, viewport.width - 100, 20); GUI.Label(labelRect, label); } GUI.EndScrollView(); } GUI.backgroundColor = Color.black; input = GUI.TextField(new Rect(0, Screen.height - 30f, Screen.width - 100f, 30), input); submitting = GUI.Button(new Rect(Screen.width - 100f, Screen.height - 30f, 100f, 30f), "Submit"); }
private void HandleInput() { string[] properties = input.Split(' '); for (int i = 0; i < commandList.Count; i++) { DebugCommandBase commandBase = commandList[i] as DebugCommandBase; if (input.Contains(commandBase.commandId)) { if (commandList[i] as DebugCommand != null) { (commandList[i] as DebugCommand).Invoke(); return; } else if (commandList[i] as DebugCommand <int> != null) { (commandList[i] as DebugCommand <int>).Invoke(int.Parse(properties[1])); return; } else if (commandList[i] as DebugCommand <string> != null) { (commandList[i] as DebugCommand <string>).Invoke(properties[1]); return; } } } }
private void HandleInput() { if (input == null || input == "") { return; } string[] properties = input.Split(' '); for (int i = 0; i < commandList.Count; i++) { DebugCommandBase commandBase = commandList[i] as DebugCommandBase; if (input.Contains(commandBase.commandId)) { if (commandList[i] as DebugCommand != null) { (commandList[i] as DebugCommand).Invoke(); return; } else if (commandList[i] as DebugCommand <string> != null) { (commandList[i] as DebugCommand <string>).Invoke(properties[1]); return; } } } Debug.LogError("Command not found"); }
//Handles the Commands private void HandleInput() { string[] properties = input.Split(' '); //Iterate over each command in the list and check if the command exists for (int i = 0; i < commandList.Count; i++) { //Cast it to the base so that we can check multiple types of commands DebugCommandBase commandBase = commandList[i] as DebugCommandBase; //If it does we invoke it if (input.Contains(commandBase.commandId)) { if (commandList[i] as DebugCommand != null) { (commandList[i] as DebugCommand).Invoke(); } else if (commandList[i] as DebugCommand <int> != null) { (commandList[i] as DebugCommand <int>).Invoke(int.Parse(properties[1])); } else if (commandList[i] as DebugCommand <float> != null) { (commandList[i] as DebugCommand <float>).Invoke(float.Parse(properties[1])); } } } }
private void OnGUI() { if (!showConsole) { return; } GUI.Box(new Rect(0, Screen.height - 140f, Screen.width, 100), ""); Rect viewport = new Rect(0, 0, Screen.width - 30, 20 * commandList.Count); scroll = GUI.BeginScrollView(new Rect(0, Screen.height - 140f + 5f, Screen.width, 90), scroll, viewport); for (int i = 0; i < commandList.Count; i++) { DebugCommandBase command = commandList[i] as DebugCommandBase; string label = $"{command.commandFormat} - { command.commandDescription}"; Rect labelRect = new Rect(5, 20 * i, viewport.width - 100, 20); GUI.Label(labelRect, label); } GUI.EndScrollView(); GUI.Box(new Rect(0, Screen.height - 40f, Screen.width, 30), ""); GUI.backgroundColor = new Color(0, 0, 0, 0); GUI.SetNextControlName("input"); input = GUI.TextField(new Rect(10, Screen.height - 35f, Screen.width - 20f, 20f), input); GUI.FocusControl("input"); if (Event.current.isKey) { switch (Event.current.keyCode) { case KeyCode.Return: case KeyCode.KeypadEnter: HandleInput(); input = ""; Event.current.Use(); break; case KeyCode.Escape: ToggleDebug(); Event.current.Use(); break; } } }
public void HandleInput() { for (int i = 0; i < commandList.Count; i++) { DebugCommandBase commandBase = commandList[i] as DebugCommandBase; if (input.Contains(commandBase.CommandID)) { if (commandList[i] as DebugCommand != null) { (commandList[i] as DebugCommand).CallCommand(); } } } }
private void HandleConsoleInput() { if (!string.IsNullOrWhiteSpace(input)) { commandLog.Add(input); consoleOutput.Add($"${input}"); lastCommandIndex = commandLog.Count; } string[] properties = input.Split(' '); //bool commandFound = false; for (int i = 0; i < commandList.Count; i++) { DebugCommandBase commandBase = commandList[i] as DebugCommandBase; if (properties[0].Contains(commandBase.commandId)) { //commandFound = true; if (commandList[i] as DebugCommand != null) { (commandList[i] as DebugCommand).Invoke(); } else if (commandList[i] as DebugCommand <float> != null) { (commandList[i] as DebugCommand <float>).Invoke(float.Parse(properties[1])); } else if (commandList[i] as DebugCommand <int> != null) { (commandList[i] as DebugCommand <int>).Invoke(int.Parse(properties[1])); } else if (commandList[i] as DebugCommand <string> != null) { (commandList[i] as DebugCommand <string>).Invoke(properties[1]); } else if (commandList[i] as DebugCommand <bool> != null) { (commandList[i] as DebugCommand <bool>).Invoke(bool.Parse(properties[1])); } break; } } // if (!commandFound) { // consoleOutput.Add ($"$ERROR! - Command not found"); // } }
void HandleInput() { if (input != null && input != string.Empty) { for (int i = 0; i < commandList.Count; i++) { DebugCommandBase commandBase = commandList[i] as DebugCommandBase; if (input.Contains(commandBase.Id)) { if (commandList[i] as DebugCommand != null) { string arg = input.Replace(commandBase.Id, string.Empty).Trim(); (commandList[i] as DebugCommand).Invoke(arg); } } } } }
private void HandleInput() { string[] properties = input.Split(' '); //handles another variable when there is a space for (int i = 0; i < commandList.Count; i++) { DebugCommandBase commandBase = commandList[i] as DebugCommandBase; if (input.Contains(commandBase.commandId)) { if (commandList[i] as DebugCommand != null) { //cast to this type and incoke the command (commandList[i] as DebugCommand).Invoke(); } else if (commandList[i] as DebugCommand <int> != null) { (commandList[i] as DebugCommand <int>).Invoke(int.Parse(properties[1])); } } } }
private void HandleInput() { string[] inputSplit = input.Split(' '); string commandWord = inputSplit[0]; string[] parameters = inputSplit.Skip(1).ToArray(); for (int i = 0; i < CommandList.commandList.Count; i++) { DebugCommandBase commandBase = CommandList.commandList[i] as DebugCommandBase; if (commandWord == commandBase.CommandID) { if (CommandList.commandList[i] is DebugCommand command) { command.Invoke(); return; } else if (CommandList.commandList[i] is DebugCommand <int> commandInt) { int parameter = 0; if (parameters.Length != 1) { Debug.LogWarning(string.Format("Could not find Parameter <int>: '{0}'\n", input)); } else if (!int.TryParse(parameters[0], out parameter)) { Debug.LogWarning(string.Format("Parameter not of Type <int>: '{0}'\n", parameters[0])); } else { commandInt.Invoke(parameter); } return; } } } Debug.LogWarning(string.Format("Could not find Command: '{0}'\n", input)); }
private void Awake() { commandLog = new List <string> (); consoleOutput = new List <string> (); HELP = new DebugCommand("help", "Shows a list of commands", "help", () => { for (int i = 0; i < commandList.Count; i++) { DebugCommandBase command = commandList[i] as DebugCommandBase; string outputText = $"{command.commandFormat} - {command.commandDescription}"; HandleConsoleOutput(outputText); } }); SET_LOOKSPEED = new DebugCommand <float> ("set_lookspeed", "Sets the look speed of the player", "set_lookspeed <value>", (x) => { ThirdPersonController controller = player.GetComponent <ThirdPersonController> (); if (controller == null) { Debug.Log("ThirdPersonController not found!"); return; } controller.LookSpeed = x; }); LIST_CAMERAS = new DebugCommand("list_cameras", "List all available cameras", "list_cameras", () => { HandleConsoleOutput(CameraManager.Instance.ListCameraNames()); }); SET_ACTIVECAMERA = new DebugCommand <int> ("set_activecamera", "Sets the active camera via camera id", "set_activecamera <id>", (id) => { CameraManager.Instance.ToggleCamera(id); }); commandList = new List <object> { HELP, SET_LOOKSPEED, LIST_CAMERAS, SET_ACTIVECAMERA }; }
/// <summary> /// Call Function Based on Input /// </summary> private void HandleInput() { // split command properties written in input string[] properties = input.Split(' '); for (int i = 0; i < commandList.Count; i++) { // check command properties to all command list id DebugCommandBase commandBase = commandList[i] as DebugCommandBase; if (properties[0] == commandBase.commandId) { // call the command if (commandList[i] as DebugCommand != null) { (commandList[i] as DebugCommand).Invoke(); } else if (commandList[i] as DebugCommand <int> != null) { (commandList[i] as DebugCommand <int>).Invoke(int.Parse(properties[1])); } } } }
private void HandleInput() { for (int i = 0; i < m_commandList.Count; i++) { DebugCommandBase cmd = m_commandList[i]; string[] split = m_input.Split(new char[] { ' ' }); string cmdName = split[0]; List <string> args = new List <string>(); if (split.Length > 1) // Has a cmdName and args { for (int j = 1; j < split.Length; j++) { if (string.IsNullOrEmpty(split[j])) { continue; } args.Add(split[j]); } } if (cmdName.Equals(cmd.Name, StringComparison.OrdinalIgnoreCase)) { if (cmd.GetType() == typeof(DebugCommand)) { ((DebugCommand)cmd).Invoke(cmdName, split); } else if (cmd.GetType() == typeof(DebugArgsCommand)) { ((DebugArgsCommand)cmd).Invoke(cmdName, args); } return; } } PrintConsole(m_input, LogType.NONE); }
public void AddCommand(DebugCommandBase command) { commandList.Add(command); commandIdList.Add(command.GetCommandId()); }