Remove Room from list

So, i'm making a lobby for my game and I already can put rooms in the list and stuff but I can't remove them from the list

here's the code that I already have and it's supposed to be working:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Photon.Realtime;



public class RoomListingMenu : MonoBehaviour
{
    [SerializeField] private Transform _content;
    [SerializeField] private RoomList _roomListing;

    public List<RoomList> _listings = new List<RoomList>();
    public void OnReceivedRoomListUpdate()
    {

        foreach (RoomInfo roomInfo in PhotonNetwork.GetRoomList())
        {
            if (roomInfo.removedFromList)
            {
                int index = _listings.FindIndex(x => x.RoomInfo.Name == roomInfo.Name);
                if(index != -1)
                {
                    Destroy(_listings[index].gameObject);
                    _listings.RemoveAt(index);
                }
                Debug.Log("Removed");
            }
            else
            {

           RoomList listing = Instantiate(_roomListing, _content);
            listing.transform.Find("RoomName").GetComponent<Text>().text = roomInfo.Name;
            listing.transform.Find("RoomP").GetComponent<Text>().text = roomInfo.PlayerCount + "/" + roomInfo.MaxPlayers;

            if (listing != null)
                listing.transform.Find("RoomName").GetComponent<Text>().text = roomInfo.Name;
                listing.transform.Find("RoomP").GetComponent<Text>().text = roomInfo.PlayerCount + "/" + roomInfo.MaxPlayers;
                _listings.Add(listing);

            Debug.Log(roomInfo.Name);
            Debug.Log(roomInfo.PlayerCount);
            Debug.Log(roomInfo.MaxPlayers);


            }
        }
    }


}

Comments

  • Hi @joao_aguiar26,

    Thank you for choosing Photon!

    I think it's better to use a Dictionary to quickly access rooms via their names.
    We also provide a snippet on the documentation here.
  • edited April 7
    Hey @JohnTube, Thanks for the help

    I saw the codes and I tried a little in here but in order to do that I need to have this:

    public override void OnRoomListUpdate(List<RoomInfo> roomList)
    {
    }

    but I can't have this because the "OnROomListUpdate" part can't be found, he got the red line under it

  • Hi @joao_aguiar26,

    I see, my bad, I did not take a good look at the snippet.
    You are using PUN Classic, here is the documentation page for PUN Classic.

    We highly recommend that you migrate to PUN 2.
    PUN Classic will be gone at some point and only PUN 2 is getting the updates.
  • I can't believe it kkkkkkkkk i tought that PUN2 only had paying versions, thank u so much @JohnTube <3 helped a LOT man
Sign In or Register to comment.