void Run_Command(string command) { // Clean whitespace. command = command.Trim(); // Ignore if blank. if (command == "") { return; } // Add to log. consoleHistory.Add(command); consoleHistoryIndex = 0; // Scroll to bottom of console. consoleScroll.y = float.MaxValue; // Save log. Save(); // Run. string[] parts = MethodHelper.CommandSplit(command, splitOn, groupStart, groupEnd); WriteToConsole(parts); string first = parts[0]; string second = parts.Length > 1 ? parts[1] : ""; // Bind a command to a keyboard. if (first == "bind") { if (parts.Length < 3) { Log("bind must be followed by a numeral and then a command.", "red"); return; } bindings[int.Parse(parts[1])] = StringHelper.ArrayToString(parts, splitOn, 2); } // On single object that has method. else if (parts.Length > 1 && byObject.ContainsKey(first)) { string method = parts[1]; // Check that method exists. if (!byObject[first].ContainsKey(method)) { Log("No method " + method + " in object " + first); return; } byObject[first][method].Invoke(ArrayHelper.SubArray(parts, 2)); } // On all objects with method. else if (byMethod.ContainsKey(first)) { string[] data = ArrayHelper.SubArray(parts, 1); foreach (ComponentMethod cm in byMethod[first]) { cm.Invoke(data); } } // Call the command on all game objects. else if (allowSendMessage) { command = StringHelper.ArrayToString(parts, splitOn, 1); // Otherwise try the built in SendMessage on all objects. foreach (GameObject go in FindObjectsOfType <GameObject>()) { go.SendMessage(parts[0], command, SendMessageOptions.DontRequireReceiver); } } else { Log("Command " + first + " not recognized"); } }