Hi! My goal is to get a room list with a second LoadBalancingClient while already in a room. I'm using PUN2 and latest Unity. After creating a public and with lobby-exposed-properties room like this (and giving it many seconds to exist, so no racing)...
Hashtable properties = new Hashtable();
properties.Add(RoomProperty.Name.ToString(), "Welcome Island X");
properties.Add(RoomProperty.Scene.ToString(), Scene.Island);
string[] lobbyExposedProperties = new string[]
{
RoomProperty.Name.ToString(),
RoomProperty.Scene.ToString(),
};
RoomOptions options = new RoomOptions();
options.MaxPlayers = (byte) 8;
options.IsVisible = true;
options.IsOpen = true;
options.CustomRoomProperties = properties;
options.CustomRoomPropertiesForLobby = lobbyExposedProperties;
PhotonNetwork.CreateRoom(null, options);
... and then creating the secondary LoadBalancingClient like this (note I'm restricting to "us" in all region settings, also in the dashboard and PUN highlight settings) ...
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
using ExitGames.Client.Photon;
public class PhotonRoomPoller : MonoBehaviourPunCallbacks, ILobbyCallbacks
{
Action callback = null;
LoadBalancingClient client = null;
public void GetRoomsInfo(Action callback)
{
this.callback = callback;
Debug.Log("Starting LoadBalancingClient...");
client = new LoadBalancingClient(PhotonNetwork.NetworkingClient.ExpectedProtocol);
client.AddCallbackTarget(this);
client.StateChanged += OnStateChanged;
client.AppId = PhotonNetwork.PhotonServerSettings.AppSettings.AppIdRealtime;
client.EnableLobbyStatistics = true;
client.ConnectToRegionMaster("us");
// if (callback != null) { callback("Hello World"); }
}
void Update()
{
if (client != null)
{
client.Service();
}
}
void OnStateChanged(ClientState previousState, ClientState state)
{
switch (state)
{
case ClientState.ConnectedToMaster:
Debug.Log("*** ConnectedToMaster");
client.OpJoinLobby(null);
break;
case ClientState.JoinedLobby:
Debug.Log("*** JoinedLobby");
break;
}
}
public override void OnRoomListUpdate(List infos)
{
Debug.Log("*** OnRoomListUpdate");
Debug.Log("Room count: " + infos.Count); // XXX
foreach (RoomInfo info in infos)
{
Debug.Log(info);
}
}
}
... I'm getting a rooms count of 0 where it says XXX, even though the proper order of ConnectedToMaster - JoinedLobby is called before, and InLobby is true at the time of checking.
What to do? Thanks!