/// <summary> /// Triggers when a match is found either through hosting or through selecting a match. Sets the lobby screen variables /// </summary> /// <param name="_message">The message from the GameSparks API</param> private void OnMatchUpdate(GameSparks.Api.Messages.MatchUpdatedMessage _message) { //Add player name to the player list StringBuilder playerList = new StringBuilder(); foreach (GameSparks.Api.Messages.MatchUpdatedMessage._Participant player in _message.Participants) { playerList.AppendLine(player.DisplayName); //Add the player number and display name to the list if (!GameSparksManager.m_PlayerIds.ContainsKey(player.Id)) { GameSparksManager.m_PlayerIds.Add(player.Id, false); } } m_PlayerCountText.GetComponent <Text>().text = _message.Participants.Count() + "/" + m_MaxPlayerCount; m_PlayerListText.GetComponent <Text>().text = playerList.ToString(); //Display the users in the room m_ReadyButton.GetComponent <Button>().interactable = true; //Allow user to ready up }
/// <summary> /// Triggers when a match is found either through hosting or through selecting a match. Sets the lobby screen variables /// </summary> /// <param name="_message">The message from the GameSparks API</param> private void OnMatchUpdate(GameSparks.Api.Messages.MatchUpdatedMessage _message) { if (m_GameStarted) { return; } //No need to update lobby screen if game is started m_TempRTSessionInfo.GetPlayerList().Clear(); //Clear player list so we can ensure it is correctly updated //Add player name to the player list StringBuilder playerList = new StringBuilder(); foreach (GameSparks.Api.Messages.MatchUpdatedMessage._Participant player in _message.Participants) { playerList.AppendLine(player.DisplayName); //Add the player number and display name to the list if (!GameSparksManager.m_PlayerIds.ContainsKey(player.Id)) { GameSparksManager.m_PlayerIds.Add(player.Id, false); } Debug.Log("Updating player list"); m_TempRTSessionInfo.GetPlayerList().Add(new RTPlayer(player.DisplayName, player.Id, (int)player.PeerId)); } m_PlayerCountText.GetComponent <Text>().text = _message.Participants.Count() + "/" + m_MaxPlayerCount; m_PlayerListText.GetComponent <Text>().text = playerList.ToString(); //Display the users in the room m_ReadyButton.GetComponent <Button>().interactable = true; //Allow user to ready up //If a player left the match, restart the ready up process if (_message?.RemovedPlayers?.Count > 0) { //If connected to RT session, disconnect GameSparksManager.Instance().EndRTSession(); //Remove player from our player list foreach (var player in _message.RemovedPlayers) { if (GameSparksManager.m_PlayerIds.ContainsKey(player)) { GameSparksManager.m_PlayerIds.Remove(player); } } } }
// Keeps the SessionInfo playerList updated with the current match participants. This is called each time the match is updated (e.g. a player joins or leaves the match). private void OnMatchUpdated(GameSparks.Api.Messages.MatchUpdatedMessage _message) { MultiplayerNetworkingManager.Instance().GetSessionInfo().UpdateRTSessionInfo(_message); }