private void DrawListWindow() { GUILayout.Label("Insira seu nome de jogador", plainStyle); playerName = GUILayout.TextField(playerName); GUILayout.Box("", GUILayout.Height(5)); GUILayout.Space(15); //If hostData is empty and and no public servers were //found then display that to the user. if (hostData == null) { GUILayout.Space(50); GUILayout.Label("Procurando servidores...", styleCentered); StartCoroutine(TalkToMasterServer()); GUILayout.Space(50); } else if (hostData.Length == 0) { GUILayout.Space(50); GUILayout.Label("Nenhum servidor encontrado.", styleCentered); GUILayout.Space(50); } //If hostData isn't empty then display the list of public //servers it has. else { //Header row GUILayout.BeginHorizontal(); GUILayout.Label("Servidores", plainStyle, GUILayout.Height(btnHeightCntWindow / 2), GUILayout.Width(sbWidth)); GUILayout.Label("Jogadores", styleCentered, GUILayout.Height((btnHeightCntWindow / 2)), GUILayout.Width(pbWidth)); //GUILayout.Label("IP Address", styleCentered, GUILayout.Height(btnHeightCntWindow/2)); GUILayout.Label("Latência", styleCentered, GUILayout.Height(btnHeightCntWindow / 2), GUILayout.Width(pbWidth)); GUILayout.EndHorizontal(); scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, false, GUILayout.MinHeight(btnHeightCntWindow)); for (int i = 0; i < hostData.Length; i++) { GUILayout.BeginHorizontal(); //Each of the available public servers are listed as buttons and the player //clicks on the relevant button to connect to a public server. if (GUILayout.Button(hostData[i].gameName, GUILayout.Height(btnHeightCntWindow / 2), GUILayout.Width(sbWidth))) { //Ensure that the player can't join a game with an empty name if (playerName == "") { playerName = "Player"; } //If the player has a name that isn't empty then attempt to join //the server. if (playerName != "") { //Connect to the selected public server and save the player's name //to player prefs. Configuration.ChangePlayerName(playerName); Configuration.SaveConfigurations(); Network.Connect(hostData[i]); } } //Dispaly the number of players currently in the server and the max number of players. if (hostData[i].connectedPlayers == hostData[i].playerLimit) playersStyle.normal.textColor = Color.red; else playersStyle.normal.textColor = Color.white; GUILayout.Label(string.Format("{0} / {1}", hostData[i].connectedPlayers, (hostData[i].playerLimit)), playersStyle, GUILayout.Height(btnHeightCntWindow / 2), GUILayout.Width(pbWidth)); //GUILayout.Label(hostData[i].ip[0].ToString(), styleCentered, GUILayout.Height(btnHeightCntWindow/2)); //List the latency of each of the public servers. If the ping isn't complete or a latency couldn't be retreived //then output N/A meaning Not Available. I think we can't ping computers within our own network that don't have //a public IP address. The ping should work on servers that are not part of our network. if (serverPingList[i].isDone) { if (serverPingList[i].time < 100) pingStyle.normal.textColor = Color.green; else pingStyle.normal.textColor = Color.red; GUILayout.Label(serverPingList[i].time.ToString(), pingStyle, GUILayout.Width(pbWidth), GUILayout.Height(btnHeightCntWindow / 2)); } else { GUILayout.Label("N/A", styleCentered, GUILayout.Height(btnHeightCntWindow / 2), GUILayout.Width(pbWidth)); } GUILayout.EndHorizontal(); GUILayout.Space(10); } GUILayout.EndScrollView(); } GUILayout.Space(15); GUILayout.Box("", GUILayout.Height(5)); //A refresh button that allows the user to refresh the list of //public servers. if (GUILayout.Button("Atualizar", GUILayout.Height(btnHeightCntWindow / 2))) { hostData = new HostData[0]; StartCoroutine(TalkToMasterServer()); } GUILayout.Space(10); if (GUILayout.Button("Voltar", GUILayout.Height(btnHeightCntWindow / 2))) { MakeConnectionWindowDefaultSize(); hostData = new HostData[0]; windowState = WindowNetworkState.MainWindow; } }
private void DrawSetupServerWindow() { GUILayout.Label("Insira o nome do servidor"); serverName = GUILayout.TextField(serverName); GUILayout.Space(5); if (GUILayout.Button("Criar e registrar servidor público", GUILayout.Height(btnHeightCntWindow))) { //Save the serverName using PlayerPrefs. PlayerPrefs.SetString("serverName", serverName); //Tell the ScoreTable script the winning criteria. //TellEveryoneWinningCriteria(winningScore); //If this computer doesn't have a public address then use NAT. Network.InitializeServer(numberOfPlayers, connectionPort, !Network.HavePublicAddress()); MasterServer.RegisterHost(gameNameType, serverName, ""); } GUILayout.Space(10); if (GUILayout.Button("Voltar", GUILayout.Height(btnHeightCntWindow))) { windowState = WindowNetworkState.MainWindow; } }
void Start() { serverName = PlayerPrefs.GetString("serverName"); if (string.IsNullOrEmpty(serverName)) serverName = "GodChallenge Server 1"; playerName = Configuration.GetPlayerName(); if (string.IsNullOrEmpty(playerName)) playerName = "Player1"; MasterServer.ipAddress = "127.0.0.1"; MasterServer.port = 23466; MasterServer.RequestHostList(gameNameType); masterServerPing = new Ping(MasterServer.ipAddress); windowState = WindowNetworkState.MainWindow; //Set GUIStyles. plainStyle.alignment = TextAnchor.MiddleLeft; plainStyle.normal.textColor = Color.white; plainStyle.wordWrap = true; //plainStyle.fontStyle = FontStyle.Bold; plainStyle.font = font; styleCentered.alignment = TextAnchor.MiddleCenter; styleCentered.normal.textColor = Color.white; styleCentered.wordWrap = true; //boldStyleCentered.fontStyle = FontStyle.Bold; styleCentered.font = font; pingStyle.alignment = TextAnchor.MiddleCenter; pingStyle.normal.textColor = Color.white; pingStyle.wordWrap = true; pingStyle.fontStyle = FontStyle.Bold; pingStyle.font = font; playersStyle.alignment = TextAnchor.MiddleCenter; playersStyle.normal.textColor = Color.white; playersStyle.wordWrap = true; playersStyle.font = font; defaultWindowHeigth = mainWindowHeight; defaultWindowWidth = mainWindowWidth; }
private void DrawMainWindow() { if (GUILayout.Button("Configurar um servidor", GUILayout.Height(btnHeightCntWindow))) windowState = WindowNetworkState.SetupServerWindow; GUILayout.Space(10); if (GUILayout.Button("Conectar a um servidor", GUILayout.Height(btnHeightCntWindow))) windowState = WindowNetworkState.ShowServerListWindow; }