public void ShowServers() { for (int i = 0; i < allServerslots.Count; i++) { Destroy(allServerslots[i]); allServerslots.Remove(allServerslots[i]); } IEnumerable <ServerInfo> servers = ServerRegistry.GetServers(); foreach (ServerInfo server in servers) { GameObject newServerBox = Instantiate(ServerBoxPrefab) as GameObject; RectTransform newServerBoxRect = newServerBox.GetComponent <RectTransform>(); ServerListObj serverListScript = newServerBox.GetComponent <ServerListObj>(); serverListScript.server = server; newServerBox.transform.SetParent(ServerRect.transform); newServerBoxRect.localPosition = new Vector3(0, (-serverRow * 50), 0); newServerBoxRect.localScale = Vector3.one; allServerslots.Add(newServerBox); serverRow++; serverRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 50 * serverRow); } serverRow = 0; Invoke("ShowServers", 15); }
public void UpdateServers() { IEnumerable <ServerInfo> servers = ServerRegistry.GetServers(); foreach (ServerInfo server in servers) { int index = allServerslots.FindIndex(item => item.GetComponent <ServerListObj>().server.host == server.host); if (index > 0) { Debug.Log("Server exist"); // element exists, do what you need } else { Debug.Log("Server dont exist"); GameObject newServerBox = Instantiate(ServerBoxPrefab) as GameObject; RectTransform newServerBoxRect = newServerBox.GetComponent <RectTransform>(); ServerListObj serverListScript = newServerBox.GetComponent <ServerListObj>(); serverListScript.server = server; newServerBox.transform.SetParent(ServerRect.transform); newServerBoxRect.localPosition = new Vector3(0, (-serverRow * 50), 0); newServerBoxRect.localScale = Vector3.one; allServerslots.Add(newServerBox); serverRow++; serverRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 50 * serverRow); } } Invoke("UpdateServers", 10); }
public void ShowServers() { for (int i = 0; i < allServerslots.Count; i++) { Destroy(allServerslots[i]); allServerslots.Remove(allServerslots[i]); } foreach (RoomInfo game in PhotonNetwork.GetRoomList()) { Debug.Log("ONE ROOM FOUND"); GameObject newServerBox = Instantiate(ServerBoxPrefab) as GameObject; RectTransform newServerBoxRect = newServerBox.GetComponent <RectTransform>(); ServerListObj serverListScript = newServerBox.GetComponent <ServerListObj>(); serverListScript.game = game; newServerBox.transform.SetParent(ServerRect.transform); newServerBoxRect.localPosition = new Vector3(0, (-serverRow * 50), 0); newServerBoxRect.localScale = Vector3.one; allServerslots.Add(newServerBox); serverRow++; serverRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 50 * serverRow); } serverRow = 0; Invoke("ShowServers", 1); }