public void RefreshServers() { netManager.RefreshHostList(); Transform serverList = serverListDisplay.transform; foreach (Transform child in serverList) { Destroy(child.gameObject); } HostData[] hostList = netManager.GetHostList(); // DONT DELETE THIS BECAUSE UNITY IS STUPID Debug.Log("REFRESHING: " + hostList.Length); if (hostList != null) { for (int i = 0; i < hostList.Length; i++) { if (hostList[i].connectedPlayers < hostList[i].playerLimit) { GameObject newButton = (GameObject)Instantiate(serverButton); Text[] texts = newButton.GetComponentsInChildren <Text>(); Debug.Log("texts length: " + texts.Length); texts[0].text = hostList[i].gameName; texts[1].text = "Players\n" + hostList[i].connectedPlayers + "/" + hostList[i].playerLimit; texts[2].text = "Password: "******"yes"; } else { texts[2].text += "no"; } newButton.transform.SetParent(serverListDisplay.transform); Button b = newButton.GetComponent <Button>(); HostData hostData = hostList[i]; b.onClick.AddListener(() => JoinGame(hostData)); } } } else { Debug.Log("no host list"); } }
// SERVER LIST void serverList() { int btnW = 160; int btnH = 30; int btnX = 200; int btnY = 200; backButtons(false); if (!Network.isClient && !Network.isServer) { if (GUI.Button(new Rect(btnX, btnY, btnW, btnH), "Host Game")) { ShowMenu(MenuIndex.HostGame); } } if (GUI.Button(new Rect(btnX + btnW + btnPadding, btnY, btnW, btnH), "Refresh List")) { networkManager.RefreshHostList(); } HostData[] hostList = networkManager.GetHostList(); if (hostList != null) { TextAnchor buttonAnchor = GUI.skin.button.alignment; GUI.skin.button.alignment = TextAnchor.MiddleLeft; for (int i = 0; i < hostList.Length; i++) { string serverInfo = hostList[i].gameName + "\t" + hostList[i].connectedPlayers + "/" + hostList[i].playerLimit; if (hostList[i].connectedPlayers < hostList[i].playerLimit) { if (GUI.Button(new Rect(btnX, btnY + (btnH + btnPadding) * (i + 1), btnW * 3, btnH), serverInfo)) { if (hostList[i].passwordProtected) { connectingToHost = hostList[i]; ShowMenu(MenuIndex.JoinGame); } else { networkManager.JoinServer(hostList[i], "asdf"); ShowMenu(MenuIndex.GameLobby); } } } } GUI.skin.button.alignment = buttonAnchor; } }