private void AddServerItem(TCServerResponse server) { //Instantiate a new button for a server GameObject newItem = Instantiate(serverItemPrefab, serverListTransform, false); newItem.GetComponent <JoinServerButton>().SetupConnectButton(server, () => ConnectToServer(server.EndPoint)); }
/// <summary> /// Sets up this button for connecting to a server /// </summary> /// <param name="server">The server details</param> /// <param name="call">The connect action</param> internal void SetupConnectButton(TCServerResponse server, Action call) { baseButton.onClick.AddListener(delegate { call(); }); gameNameText.text = server.GameName.String; mapNameText.text = server.SceneName; pingText.text = "0"; playerCountText.text = $"{server.CurrentAmountOfPlayers}/{server.MaxPlayers}"; }
/// <summary> /// Adds a <see cref="TCServerResponse" /> to the list of servers /// </summary> /// <param name="server"></param> public void AddServer(TCServerResponse server) { //We are connecting to a server... if (NetworkManager.singleton.mode == NetworkManagerMode.ClientOnly) { return; } //If the server already exists in the list then ignore it if (servers.Any(x => Equals(x.EndPoint, server.EndPoint))) { return; } //Add the server to the list servers.Add(server); AddServerItem(server); statusText.gameObject.SetActive(false); Logger.Debug("Found server at {Address}", server.EndPoint.Address); }