예제 #1
0
 private void HideJoinBattleMenu()
 {
     if (currentLobby != null)
     {
         LeaveLobby(currentLobby.Id);
         currentLobby = null;
     }
     StopCoroutine(battlePoller);
     this.gameObject.SetActive(false);
 }
예제 #2
0
        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));
            }
        }
예제 #3
0
        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);
        }
예제 #4
0
        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());
        }