Quantcast
Channel: Photon Unity Networking (PUN) — Photon Engine
Viewing all articles
Browse latest Browse all 8947

PhotonNetwork.GetRoomList() gone in PUN2. How can I modify this to work again?

$
0
0
Pretty Much what the title says. I've already spent hours trying. I'm still new to photon and followed a tutorial a while ago to get this working. I'm not sure how to cache the room lists. Any help would be appreciated. namespace UnityEngine.UI.Extensions { using System.Collections.Generic; using UnityEngine; public class RoomLayoutGroup : MonoBehaviour { [SerializeField] private GameObject _roomListingPrefab; private GameObject RoomListingPrefab { get { return _roomListingPrefab; } } private List _roomListingButtons = new List(); private List RoomListingButtons { get { return _roomListingButtons; } } private void OnReceivedRoomListUpdate() { RoomInfo[] rooms = PhotonNetwork.GetRoomList(); foreach (RoomInfo room in rooms) { RoomReceived(room); } RemoveOldRooms(); } private void RoomReceived(RoomInfo room) { int index = RoomListingButtons.FindIndex(x => x.RoomName == room.Name); if (index == -1) { if (room.IsVisible && room.PlayerCount < room.MaxPlayers) { GameObject roomListingObj = Instantiate(RoomListingPrefab); roomListingObj.transform.SetParent(transform, false); RoomListing roomListing = roomListingObj.GetComponent(); RoomListingButtons.Add(roomListing); index = (RoomListingButtons.Count - 1); } } if (index != -1) { RoomListing roomListing = RoomListingButtons[index]; roomListing.SetRoomNameText(room.Name); roomListing.Updated = true; } } private void RemoveOldRooms() { List removeRooms = new List(); foreach (RoomListing roomListing in RoomListingButtons) { if (!roomListing.Updated) removeRooms.Add(roomListing); else roomListing.Updated = false; } foreach (RoomListing roomListing in removeRooms) { GameObject roomListingObj = roomListing.gameObject; RoomListingButtons.Remove(roomListing); Destroy(roomListingObj); } } } }

Viewing all articles
Browse latest Browse all 8947

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>