コード例 #1
0
 protected virtual void OnDestroy()
 {
     if (JoinedLobby != null && JoinedLobby.Listener.Equals(this))
     {
         JoinedLobby.SetListener(null);
     }
 }
コード例 #2
0
        public virtual void Initialize(JoinedLobby lobby)
        {
            JoinedLobby = lobby;

            gameObject.SetActive(true);

            Setup(lobby);
        }
コード例 #3
0
 public virtual void OnStartGameClick()
 {
     JoinedLobby.StartGame((successful, error) => {
         if (!successful)
         {
             Logs.Error(error);
         }
     });
 }
コード例 #4
0
        /// <summary>
        ///     Invoked, when client clicks "Play" button
        /// </summary>
        public virtual void OnPlayClick()
        {
            JoinedLobby.GetLobbyRoomAccess((access, error) => {
                if (access == null)
                {
                    Logs.Error("Failed: " + error);
                    return;
                }

                OnRoomAccessReceived(access);
            });
        }
コード例 #5
0
        public virtual void Setup(JoinedLobby lobby)
        {
            Reset();

            _wasGameRunningWhenOpened = lobby.State == LobbyState.GameInProgress;

            CurrentUser = lobby.Data.CurrentUserUsername;

            LobbyName.text = lobby.LobbyName;
            LobbyType.text = lobby.Data.LobbyType;

            Teams.Clear();
            Users.Clear();

            // Setup teams
            foreach (var team in lobby.Teams)
            {
                Teams.Add(team.Key, CreateTeamView(team.Key, team.Value));
            }

            // Setup users
            foreach (var player in lobby.Members)
            {
                Users.Add(player.Key, CreateMemberView(player.Value));
            }

            // Setup controls
            if (PropControllers != null)
            {
                PropControllers.Setup(JoinedLobby.Data.Controls);
            }

            // Current player's ready state
            if (lobby.Members.ContainsKey(CurrentUser))
            {
                IsReady = lobby.Members[CurrentUser].IsReady;
            }

            OnLobbyStateChange(lobby.State);
            OnMasterChanged(lobby.Data.GameMaster);

            UpdateTeamJoinButtons();
            UpdateReadyButton();
            UpdateStartGameButton();
            UpdatePlayerCount();
        }
コード例 #6
0
        /// <summary>
        /// Sends a request to join a lobby
        /// </summary>
        public void JoinLobby(int lobbyId, JoinLobbyCallback callback, IClientSocket connection)
        {
            // Send the message
            connection.SendMessage((short)MsfOpCodes.JoinLobby, lobbyId, (status, response) =>
            {
                if (status != ResponseStatus.Success)
                {
                    callback.Invoke(null, response.AsString("Unknown Error"));
                    return;
                }

                var data = response.Deserialize(new LobbyDataPacket());

                var key = data.LobbyId + ":" + connection.Peer.Id;

                if (_joinedLobbies.ContainsKey(key))
                {
                    // If there's already a lobby
                    callback.Invoke(_joinedLobbies[key], null);
                    return;
                }

                var joinedLobby = new JoinedLobby(data, connection);

                LastJoinedLobby = joinedLobby;

                // Save the lobby
                _joinedLobbies[key] = joinedLobby;

                callback.Invoke(joinedLobby, null);

                if (LobbyJoined != null)
                {
                    LobbyJoined.Invoke(joinedLobby);
                }
            });
        }
コード例 #7
0
 public virtual void OnLeaveClick()
 {
     JoinedLobby.Leave();
 }
コード例 #8
0
 public virtual void OnReadyClick()
 {
     JoinedLobby.SetReadyStatus(!IsReady);
 }