1 year ago
#329668
PULUTUR
Live playercount in Photon rooms
I have a project where we use photon to make rooms for people to join.
I got it working to show the playercount, but the thing is it doesnt update the playercount live. Is it possible to make the room show a live playercount in the room browser. Cause at the moment it only updates it when you disconnect and reconnect to the network. I've tried some work arounds but nothing seems to work.
^^This is how it currently looks. It only updates upon reconnecting to the server.^^
public override void OnRoomListUpdate(List<RoomInfo> roomList)
{
foreach (RoomInfo info in roomList)
{
//Removed from rooms list
if (info.RemovedFromList)
{
int index = _listings.FindIndex(x => x.RoomInfo.Name == info.Name);
if(index != -1)
{
Destroy(_listings[index].gameObject);
_listings.RemoveAt(index);
}
}
//Added to rooms list
else
{
int index = _listings.FindIndex(x => x.RoomInfo.Name == info.Name);
if (index == -1)
{
RoomListing listing = Instantiate(_roomListing, _content);
if (listing != null)
{
listing.SetRoomInfo(info);
_listings.Add(listing);
}
}
else
{
//Modify listing here
}
}
}
}
^^This is how our code looks like when a room gets created/removed.^^
public class RoomListing : MonoBehaviour
{
[SerializeField]
private TextMeshProUGUI _text;
public RoomInfo RoomInfo { get; private set; }
public void SetRoomInfo(RoomInfo roomInfo)
{
RoomInfo = roomInfo;
_text.text = roomInfo.PlayerCount + "/" +roomInfo.MaxPlayers + "," + roomInfo.Name;
}
public void OnClick_Button()
{
PhotonNetwork.JoinRoom(RoomInfo.Name);
}
}
^^This is the code for adding the information of the room (such as the name, max players and in this case also the playercount.)
Does anybody know what we could do to make the playercount update live? We tried numerous things, with no succes sadly.
c#
unity-game-engine
photon
0 Answers
Your Answer