protected virtual void OnDestroy() { if (JoinedLobby != null && JoinedLobby.Listener.Equals(this)) { JoinedLobby.SetListener(null); } }
public virtual void Initialize(JoinedLobby lobby) { JoinedLobby = lobby; gameObject.SetActive(true); Setup(lobby); }
public virtual void OnStartGameClick() { JoinedLobby.StartGame((successful, error) => { if (!successful) { Logs.Error(error); } }); }
/// <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); }); }
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(); }
/// <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); } }); }
public virtual void OnLeaveClick() { JoinedLobby.Leave(); }
public virtual void OnReadyClick() { JoinedLobby.SetReadyStatus(!IsReady); }