How can I list rooms in Unity? (PUN2)

Sebastián García picture Sebastián García · Oct 13, 2018 · Viewed 8.5k times · Source

I need to list the romos there are in my lobby scene. For now, this is the code I've used but I don't know why it isnt working. Is this the correct way?

public override void OnRoomListUpdate(List<RoomInfo> roomList)
     {
         print(roomList.Count + " Rooms");
         base.OnRoomListUpdate(roomList);
         foreach (var Item in roomList)
         {
             RoomName = Item.Name;
             PlayerAmount = Item.PlayerCount;
             MaxPlayers = Item.MaxPlayers;
             PhotonNetwork.Instantiate("RoomPrefab", transform.position, transform.rotation);
             RoomPrefab.transform.Find("RoomName").GetComponent<Text>().text = RoomName;
             RoomPrefab.transform.Find("PlayerInt").GetComponent<Text>().text = PlayerAmount.ToString();
             if(MaxPlayers == 4)
             {
                 GameObject.Find("IPlayerA").GetComponent<Image>().sprite = Four;
             }
             else if (MaxPlayers == 2)
             {
                 GameObject.Find("IPlayerA").GetComponent<Image>().sprite = Two;
             }
             else if (MaxPlayers == 3)
             {
                 GameObject.Find("IPlayerA").GetComponent<Image>().sprite = Three;
             }
             RoomPrefab.transform.SetParent(ScrollView.transform, false);
         }
     }

I need to specify that I'm using Photon's PUN2, so GetRoomList won't work.

Answer

Saloni Bhoi picture Saloni Bhoi · Feb 7, 2019

PhotonNetwork.GetRoomList() is gone in PUN2. You get rooms list and updates from ILobbyCallbacks.OnRoomListUpdate(List roomList) callback. You can optionally cache it, update it and clear it when needed.

Also you can check updates from PUN to PUN2 here https://doc.photonengine.com/en-us/pun/v2/getting-started/migration-notes