private void HideJoinBattleMenu() { if (currentLobby != null) { LeaveLobby(currentLobby.Id); currentLobby = null; } StopCoroutine(battlePoller); this.gameObject.SetActive(false); }
private IEnumerator StartPollingLobby() { while (true) { currentLobby = Network.GetLobby(currentLobby.Id); UpdatePlayersAddresses(currentLobby.Players.Select(p => p.Address).ToList()); if (currentLobby.Players.All(p => p.IsReady)) { FinishMatchmaking(); } yield return(new WaitForSeconds(2f)); } }
private bool LeaveLobby(int id) { if (!Network.LeaveLobby(id)) { return(false); } LeaveBtn.onClick.RemoveAllListeners(); UpdatePlayersAddresses(new List <string>()); UpdateChosenBattleText(); currentLobby = null; StopCoroutine(lobbyPoller); thisPlayerIndex = -1; thisPlayerReady = false; ChosenBattleText.text = ""; return(true); }
private void JoinBattle(int id) { if (currentLobby != null) { if (!LeaveLobby(currentLobby.Id)) { return; } } if (!Network.JoinLobby(id)) { return; } currentLobby = Network.GetLobby(id); UpdatePlayersAddresses(currentLobby.Players.Select(p => p.Address).ToList()); UpdateChosenBattleText(); thisPlayerIndex = currentLobby.PlayersCount; LeaveBtn.onClick.AddListener(() => LeaveLobby(id)); lobbyPoller = StartCoroutine(StartPollingLobby()); }