public void SetData(NetworkDiscoveryData data) { Data = data; if (textRoomName != null) { textRoomName.text = string.IsNullOrEmpty(data.roomName) ? "Untitled" : data.roomName; } if (textPlayerName != null) { textPlayerName.text = data.playerName; } if (textSceneName != null) { textSceneName.text = BaseNetworkGameInstance.GetMapNameByScene(data.sceneName); } if (textPlayerCount != null) { textPlayerCount.text = data.numPlayers + "/" + data.maxPlayers; } if (textRoomState != null) { switch ((SimplePhotonNetworkManager.RoomState)data.state) { case SimplePhotonNetworkManager.RoomState.Waiting: textRoomState.text = roomStateWaiting; break; case SimplePhotonNetworkManager.RoomState.Playing: textRoomState.text = roomStatePlaying; break; } } BaseNetworkGameRule gameRule = null; if (textGameRule != null && BaseNetworkGameInstance.GameRules.TryGetValue(data.gameRule, out gameRule)) { textGameRule.text = gameRule == null ? "" : gameRule.Title; } if (textBotCount != null) { textBotCount.text = data.botCount.ToString("N0"); textBotCount.gameObject.SetActive(gameRule != null && gameRule.HasOptionBotCount); } if (textMatchTime != null) { textMatchTime.text = data.matchTime.ToString("N0"); textMatchTime.gameObject.SetActive(gameRule != null && gameRule.HasOptionMatchTime); } if (textMatchKill != null) { textMatchKill.text = data.matchKill.ToString("N0"); textMatchKill.gameObject.SetActive(gameRule != null && gameRule.HasOptionMatchKill); } if (textMatchScore != null) { textMatchScore.text = data.matchScore.ToString("N0"); textMatchScore.gameObject.SetActive(gameRule != null && gameRule.HasOptionMatchScore); } if (hasPasswordObject != null) { hasPasswordObject.SetActive(!string.IsNullOrEmpty(data.roomPassword)); } }
private void UpdateRoomData() { var room = PhotonNetwork.room; var customProperties = room.CustomProperties; var roomName = (string)customProperties[SimplePhotonNetworkManager.CUSTOM_ROOM_ROOM_NAME]; var playerId = (string)customProperties[SimplePhotonNetworkManager.CUSTOM_ROOM_PLAYER_ID]; var playerName = (string)customProperties[SimplePhotonNetworkManager.CUSTOM_ROOM_PLAYER_NAME]; var sceneName = (string)customProperties[SimplePhotonNetworkManager.CUSTOM_ROOM_SCENE_NAME]; var state = (byte)customProperties[SimplePhotonNetworkManager.CUSTOM_ROOM_STATE]; if (textRoomName != null) { textRoomName.text = string.IsNullOrEmpty(roomName) ? "Untitled" : roomName; } if (textPlayerName != null) { textPlayerName.text = playerName; } if (textSceneName != null) { textSceneName.text = BaseNetworkGameInstance.GetMapNameByScene(sceneName); } if (textPlayerCount != null) { textPlayerCount.text = room.PlayerCount + "/" + room.MaxPlayers; } if (textRoomState != null) { switch ((SimplePhotonNetworkManager.RoomState)state) { case SimplePhotonNetworkManager.RoomState.Waiting: textRoomState.text = roomStateWaiting; break; case SimplePhotonNetworkManager.RoomState.Playing: textRoomState.text = roomStatePlaying; break; } } object gameRuleObject; BaseNetworkGameRule gameRule = null; if (textGameRule != null && customProperties.TryGetValue(BaseNetworkGameManager.CUSTOM_ROOM_GAME_RULE, out gameRuleObject) && BaseNetworkGameInstance.GameRules.TryGetValue(gameRuleObject.ToString(), out gameRule)) { textGameRule.text = gameRule == null ? "Unknow" : gameRule.Title; } waitingPlayerListRoot.SetActive(!gameRule.IsTeamGameplay); waitingPlayerTeamAListRoot.SetActive(gameRule.IsTeamGameplay); waitingPlayerTeamBListRoot.SetActive(gameRule.IsTeamGameplay); object botCountObject; if (textBotCount != null && customProperties.TryGetValue(BaseNetworkGameManager.CUSTOM_ROOM_GAME_RULE_BOT_COUNT, out botCountObject)) { textBotCount.text = ((int)botCountObject).ToString("N0"); textBotCount.gameObject.SetActive(gameRule != null && gameRule.HasOptionBotCount); } object matchTimeObject; if (textMatchTime != null && customProperties.TryGetValue(BaseNetworkGameManager.CUSTOM_ROOM_GAME_RULE_MATCH_TIME, out matchTimeObject)) { textMatchTime.text = ((int)matchTimeObject).ToString("N0"); textMatchTime.gameObject.SetActive(gameRule != null && gameRule.HasOptionMatchTime); } object matchKillObject; if (textMatchKill != null && customProperties.TryGetValue(BaseNetworkGameManager.CUSTOM_ROOM_GAME_RULE_MATCH_KILL, out matchKillObject)) { textMatchKill.text = ((int)matchKillObject).ToString("N0"); textMatchKill.gameObject.SetActive(gameRule != null && gameRule.HasOptionMatchKill); } object matchScoreObject; if (textMatchScore != null && customProperties.TryGetValue(BaseNetworkGameManager.CUSTOM_ROOM_GAME_RULE_MATCH_SCORE, out matchScoreObject)) { textMatchScore.text = ((int)matchScoreObject).ToString("N0"); textMatchScore.gameObject.SetActive(gameRule != null && gameRule.HasOptionMatchScore); } HostPlayerID = playerId; }