bool Check_Player_Name() { if (Player_Name != "") { Chat_Script.PlayerName = Player_Name; return(true); } else { Popup_Script.Popup_Box("Please enter your player name", "Player name required", 5.0f); return(false); } }
void MakeServerWindow(int id) { if (Network.peerType == NetworkPeerType.Disconnected) { GUILayout.BeginHorizontal(); GUILayout.Space(10); GUILayout.Label("Server name:"); Server_Name = GUILayout.TextField(Server_Name, 20, GUILayout.Width(130)); GUILayout.Space(10); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(10); GUILayout.Label("Player name:"); Player_Name = GUILayout.TextField(Player_Name, 20, GUILayout.Width(130)); GUILayout.Space(10); GUILayout.EndHorizontal(); GUILayout.Space(10); GUILayout.BeginHorizontal(); GUILayout.Space(10); // Start a new server if (GUILayout.Button("Start Server") && Check_Player_Name()) { if (Server_Name == "") { Popup_Script.Popup_Box("Please enter the server's name", "Problem starting server...", 5.0f); } else { GetComponent <AudioSource>().PlayOneShot(GetComponent <Audio>().JoinGame); Network.InitializeServer(5, Connection_Port, Use_Nat); MasterServer.RegisterHost(Game_Name, Server_Name, "Host: " + Player_Name); } } // Refresh hosts if (GUILayout.Button("Refresh available Servers") || Time.realtimeSinceStartup > Last_Host_List_Request + Host_List_Refresh_Timeout) { MasterServer.ClearHostList(); MasterServer.RequestHostList(Game_Name); Last_Host_List_Request = Time.realtimeSinceStartup; } GUILayout.FlexibleSpace(); GUILayout.Space(10); GUILayout.EndHorizontal(); } else { if (!Is_Ingame && Network.peerType == NetworkPeerType.Server) { if (GUILayout.Button("Start Game")) { Is_Ingame = true; // register as an in progress game Network.maxConnections = 0; MasterServer.RegisterHost(Game_Name, Server_Name, "In Progress"); //MasterServer.UnregisterHost(); //LOAD LEVEL 1! // Make sure no old RPC calls are buffered and then send load level command Network.RemoveRPCsInGroup(0); Network.RemoveRPCsInGroup(1); Network.Instantiate(GameDirector, transform.position, transform.rotation, 0); // Load level with incremented level prefix (for view IDs) networkView.RPC("Load_Level", RPCMode.AllBuffered, Supported_Levels[0], Last_Level_Prefix + 1); } } if (GUILayout.Button("Disconnect")) { GetComponent <AudioSource>().PlayOneShot(GetComponent <Audio>().LeaveGame); Network.Disconnect(); MasterServer.UnregisterHost(); } GUILayout.FlexibleSpace(); } GUI.DragWindow(new Rect(0, 0, 1000, 1000)); }
void MakeServerWindow(int id) { if (Network.peerType == NetworkPeerType.Disconnected) { GUILayout.BeginHorizontal(); GUILayout.Space(10); GUILayout.Label("Server name:"); Server_Name = GUILayout.TextField(Server_Name, 20, GUILayout.Width(130)); GUILayout.Space(10); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(10); GUILayout.Label("Player name:"); Player_Name = GUILayout.TextField(Player_Name, 20, GUILayout.Width(130)); GUILayout.Space(10); GUILayout.EndHorizontal(); GUILayout.Space(10); GUILayout.BeginHorizontal(); GUILayout.Space(10); // Start a new server if (GUILayout.Button("Start Server") && Check_Player_Name()) { if (Server_Name == "") { Popup_Script.Popup_Box("Please enter the server's name", "Problem starting server...", 5.0f); } else { Network.InitializeServer(5, Connection_Port, Use_Nat); MasterServer.RegisterHost(Game_Name, Server_Name, Player_Name); Resize_Window_Rect(); } } // Refresh hosts if (GUILayout.Button("Refresh available Servers") || Time.realtimeSinceStartup > Last_Host_List_Request + Host_List_Refresh_Timeout) { MasterServer.RequestHostList(Game_Name); Last_Host_List_Request = Time.realtimeSinceStartup; } GUILayout.FlexibleSpace(); GUILayout.Space(10); GUILayout.EndHorizontal(); } else { if (!Is_Ingame && Network.peerType == NetworkPeerType.Server) { if (GUILayout.Button("Start Game")) { Is_Ingame = true; // remove from gamelist so no more people may join MasterServer.UnregisterHost(); //LOAD LEVEL 1! // Make sure no old RPC calls are buffered and then send load level command Network.RemoveRPCsInGroup(0); Network.RemoveRPCsInGroup(1); // Load level with incremented level prefix (for view IDs) networkView.RPC("Load_Level", RPCMode.AllBuffered, Supported_Levels[0], Last_Level_Prefix + 1); Resize_Window_Rect(); } } if (GUILayout.Button("Disconnect")) { Network.Disconnect(); MasterServer.UnregisterHost(); Resize_Window_Rect(); } GUILayout.FlexibleSpace(); } GUI.DragWindow(new Rect(0, 0, 1000, 1000)); }