Photon: How to access customRoomPropertiesForLobby after creating a room?
Options
Hey guys, I want to readout what was written into my customRoomPropertiesForLobby. I have a Set-Function which get called by an InputField:
public void setRoomUrl(string str)
{
roomURL = str;
myRoomProperties[0] = roomURL;
}
Then I have this line:
string[] myRoomProperties = new string[0];
And then I create a Room:
public void PlayButton()
{
RoomOptions roomOptions = new RoomOptions() {
maxPlayers = maxPlayer,
isOpen = true,
isVisible = true,
customRoomPropertiesForLobby = myRoomProperties};
PhotonNetwork.CreateRoom(roomName, roomOptions, TypedLobby.Default);
}
So lets say I tipped www.google.com in it, and it is now in "customRoomPropertiesForLobby" saved. How can I now access the information? I want to get www.google.com out from "customRoomPropertiesForLobby" in another script
I do not know if all this is just too inconvenient. The basic idea was, that I tip in a InputField the URL of my room-file. And this string has to be sync with photon, so that the room will load also at clients computer.
And this is my RoomImport-Script (I dont know if its important to see). "BundleURL" hast to get the URL of my room-file:
public class RoomImport : Photon.MonoBehaviour
{
GameObject roomURL = GameObject.Find("RoomURL");
public string BundleURL = "";
public string AssetName = "_CrvrUserRoom";
public int version;
void Awake()
{
}
void StartThis(string str)
{
StartCoroutine(DownloadAndCache());
}
IEnumerator DownloadAndCache()
{
// Wait for the Caching system to be ready
while (!Caching.ready)
yield return null;
// Load the AssetBundle file from Cache if it exists with the same version or download and store it in the cache
using (WWW www = WWW.LoadFromCacheOrDownload(BundleURL, version))
{
yield return www;
if (www.error != null)
throw new Exception("WWW download had an error:" + www.error);
AssetBundle bundle = www.assetBundle;
if (AssetName == "")
Instantiate(bundle.mainAsset);
else
Instantiate(bundle.LoadAsset(AssetName));
// Unload the AssetBundles compressed contents to conserve memory
bundle.Unload(false);
} // memory is freed from the web stream (www.Dispose() gets called implicitly)
}
}
public void setRoomUrl(string str)
{
roomURL = str;
myRoomProperties[0] = roomURL;
}
Then I have this line:
string[] myRoomProperties = new string[0];
And then I create a Room:
public void PlayButton()
{
RoomOptions roomOptions = new RoomOptions() {
maxPlayers = maxPlayer,
isOpen = true,
isVisible = true,
customRoomPropertiesForLobby = myRoomProperties};
PhotonNetwork.CreateRoom(roomName, roomOptions, TypedLobby.Default);
}
So lets say I tipped www.google.com in it, and it is now in "customRoomPropertiesForLobby" saved. How can I now access the information? I want to get www.google.com out from "customRoomPropertiesForLobby" in another script
I do not know if all this is just too inconvenient. The basic idea was, that I tip in a InputField the URL of my room-file. And this string has to be sync with photon, so that the room will load also at clients computer.
And this is my RoomImport-Script (I dont know if its important to see). "BundleURL" hast to get the URL of my room-file:
public class RoomImport : Photon.MonoBehaviour
{
GameObject roomURL = GameObject.Find("RoomURL");
public string BundleURL = "";
public string AssetName = "_CrvrUserRoom";
public int version;
void Awake()
{
}
void StartThis(string str)
{
StartCoroutine(DownloadAndCache());
}
IEnumerator DownloadAndCache()
{
// Wait for the Caching system to be ready
while (!Caching.ready)
yield return null;
// Load the AssetBundle file from Cache if it exists with the same version or download and store it in the cache
using (WWW www = WWW.LoadFromCacheOrDownload(BundleURL, version))
{
yield return www;
if (www.error != null)
throw new Exception("WWW download had an error:" + www.error);
AssetBundle bundle = www.assetBundle;
if (AssetName == "")
Instantiate(bundle.mainAsset);
else
Instantiate(bundle.LoadAsset(AssetName));
// Unload the AssetBundles compressed contents to conserve memory
bundle.Unload(false);
} // memory is freed from the web stream (www.Dispose() gets called implicitly)
}
}
0
Comments
-
Read "Custom Properties" here:
https://doc.photonengine.com/en/pun/current/tutorials/synchronization-and-state
Don't forget to pass list of game properties names in CreateRoom call. I suspect that you pass empty list there instead of actual names.1 -
ok, I got it yeah I didn't know that I has to give it a name and a value. I fixed it with this line:
RoomOptions roomOptions = new RoomOptions() { maxPlayers = maxPlayer, isOpen = true, isVisible = true, customRoomProperties = new ExitGames.Client.Photon.Hashtable() { { "prop1", roomURL } } };0