string ProcessCommand(string command) { // string invalidSyntaxString = "Invalid syntax."; string[] words = command.Split(" ".ToCharArray()); int numWords = words.Length; // string restOfTheCommand = command.Substring (command.IndexOf (' ') + 1); string response = ""; // var networkManager = UnityEngine.Networking.NetworkManager.singleton; if (2 == numWords && words [0] == "change_scene") { string newSceneName = words [1]; if (NetworkStatus.IsServerStarted()) { if (newSceneName.Length < 1) { response += "Invalid scene name."; } else { bool mapExists = MapCycle.singleton.mapCycleList.Contains(newSceneName); if (mapExists) { response += "Changing scene to " + newSceneName + "."; SceneChanger.ChangeScene(newSceneName); } else { response += "This scene does not exist."; } } } } else if (words [0] == "list_maps") { if (NetworkStatus.IsServerStarted()) { var maps = MapCycle.singleton.mapCycleList; foreach (string mapName in maps) { response += mapName + "\n"; } } else { if (NetworkStatus.IsClientConnected()) { // Ask server to display all available maps. Player.local.CmdListMaps(); } } } else if (words [0] == "timeleft") { if (NetworkStatus.IsServerStarted()) { response += MapCycle.singleton.GetTimeLeftAsString(); } } else if (words [0] == "nextmap") { if (NetworkStatus.IsServerStarted()) { response += MapCycle.singleton.GetNextMap(); } } return(response); }
static void DrawConsole() { int consoleWidth = Screen.width; int consoleHeight = Screen.height / 2; // Draw rectangle in background. GUI.Box(new Rect(0, 0, consoleWidth, consoleHeight), ""); // Draw some statistics above console GUILayout.BeginArea(new Rect(0, 0, Screen.width, 30)); GUILayout.BeginHorizontal(); // display fps GUILayout.Label("FPS: " + GameManager.GetAverageFps()); // display uptime if (NetworkStatus.IsServerStarted()) { GUILayout.Label(" uptime: " + Utilities.Utilities.FormatElapsedTime(Time.realtimeSinceStartup)); } // let anybody else display their own stats try { onDrawStats(); } catch (System.Exception ex) { Debug.LogException(ex); } // Display network statistics for client if (NetworkStatus.IsClientConnected() && !NetworkStatus.IsHost()) { NetworkConnection conn = NetManager.GetClient().connection; byte error = 0; GUILayout.Label(" ping: " + NetworkTransport.GetCurrentRtt(conn.hostId, conn.connectionId, out error) + " ms"); GUILayout.Label(" lost_packets: " + NetworkTransport.GetNetworkLostPacketNum(conn.hostId, conn.connectionId, out error)); GUILayout.Label(" received_rate: " + NetworkTransport.GetPacketReceivedRate(conn.hostId, conn.connectionId, out error)); GUILayout.Label(" sent_rate: " + NetworkTransport.GetPacketSentRate(conn.hostId, conn.connectionId, out error)); } GUILayout.EndHorizontal(); GUILayout.EndArea(); m_consoleScrollPosition = GUILayout.BeginScrollView( m_consoleScrollPosition, GUILayout.Width(consoleWidth), GUILayout.Height(consoleHeight)); /* * // Display player information * if( networkManager.IsServer() ) { * * GUILayout.Label("Players"); * GUILayout.Label("name\t\t | health\t | kills\t | deaths\t | ping"); * foreach ( Player player in networkManager.players ) { * * string s = ""; * s += player.playerName + "\t "; * if (player.mainNetworkScript != null) { * s += player.mainNetworkScript.health + "\t " + player.mainNetworkScript.numKills + "\t " + player.mainNetworkScript.numDeaths ; * } * s += "\t 0 ms"; * * GUILayout.Label( s ); * } * } */ // Draw log string // if( logString != "" ) { { /* * GUIStyle style = new GUIStyle( GUI.skin.textArea ); * // style.wordWrap = true; * style.richText = true ; * GUILayout.Space(25); * GUILayout.TextArea( logString, style, GUILayout.MinHeight (consoleHeight - 30) ); */ GUILayout.Space(30); GUILayout.Label(m_logString); } GUILayout.EndScrollView(); GUILayout.BeginHorizontal(); string textToProcess = ""; // Edit box for commands input. GUI.SetNextControlName("commands_input"); m_consoleCommandText = GUILayout.TextField(m_consoleCommandText, 1000, GUILayout.Width(Screen.width / 4), GUILayout.Height(40)); if (Event.current.isKey && GUI.GetNameOfFocusedControl() == "commands_input") { if (Event.current.keyCode == KeyCode.UpArrow) { // up arrow pressed and edit box is in focus BrowseHistoryBackwards(); } else if (Event.current.keyCode == KeyCode.DownArrow) { // down arrow pressed and edit box is in focus BrowseHistoryForwards(); } else if (Event.current.keyCode == KeyCode.Return) { // enter pressed textToProcess = m_consoleCommandText; } } // submit button // bool submited = GUILayout.Button( "Submit", GUILayout.Width(60), GUILayout.Height(40) ); bool submited = GameManager.DrawButtonWithCalculatedSize("Submit"); if (submited) { textToProcess = m_consoleCommandText; } GUILayout.EndHorizontal(); if (textToProcess != "") { SubmittedText(textToProcess); // clear input text box SetInputBoxText(""); } }