我需要列出我的大堂场景中的小房间。现在,这是我使用的代码,但我不知道为什么它不起作用。这是正确的方法吗?

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);
         }
     }


我需要指定我使用的是Photon的PUN2,因此GetRoomList无法正常工作。

最佳答案

PhotonNetwork.GetRoomList()在PUN2中消失了。您可以从ILobbyCallbacks.OnRoomListUpdate(List roomList)回调获取房间列表和更新。您可以选择对其进行缓存,更新并在需要时清除它。

您也可以在此处检查从PUN到PUN2的更新
https://doc.photonengine.com/en-us/pun/v2/getting-started/migration-notes

关于c# - 如何在Unity中列出房间? (PUN2),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52793933/

10-10 16:16