Is it Possible to Show Custom Properties List which are being set in a room?
The whole answer can be found below.
Try Our
Documentation
Please check if you can find an answer in our extensive documentation on PUN.
Join Us
on Discord
Meet and talk to our staff and the entire Photon-Community via Discord.
Read More on
Stack Overflow
Find more information on Stack Overflow (for Circle members only).
Is it Possible to Show Custom Properties List which are being set in a room?
Sikandar
2020-05-17 23:57:08
Hi,
I am setting Room Custom Room Properties on Runtime and it works in Console when I print them, However I want to show them as soon as they're being created.
Here's my code to set the custom room properties:
private ExitGames.Client.Photon.Hashtable _BookmarkData = new ExitGames.Client.Photon.Hashtable();
public void SetBookmarkData()
{
id++;
_BookmarkData[id] = inputTextField.text;
PhotonNetwork.LocalPlayer.CustomProperties = _BookmarkData;
Debug.Log("ID: " + id);
Debug.Log("Text: " + _BookmarkData[id]);
}
Code which Doesn't Work (to show Custom Properties)
public class PanelBookmark_Manager : MonoBehaviour
{
public Player Player { get; private set; }
[SerializeField]
private TextMeshProUGUI text_bookarmarkText;
private void Start()
{
text_bookarmarkText = GetComponent<TextMeshProUGUI>();
}
private void SetPlayerInfo(Player player)
{
Debug.Log("Working?");
text_bookarmarkText.text = player.CustomProperties[1].ToString(); // 1 is a static just to check if it works.
}
}
This code doens't display properties/values that are being set.
Any help would be appreciated.
Thanks in advance.
Comments
Hi,
You can catch custom room and custom player properties change immediately using:
https://doc-api.photonengine.com/en/pun/v2/interface_photon_1_1_realtime_1_1_i_in_room_callbacks.html#ace378cf7df21ab802b2a0d144264e6c5
Bye,
Jean
Hi Jean,
Thank you for your response.
A small would be great.
Regards.
Hi,
Can you rephrase, I am not sure I understand...
Bye
Jean
Hi Jean,
Sorry my bad. A small example would be great I meant.
Update
So far I have been able to display custom player properties but these are displayed locally only not sent on server, is there a setting that needs to be changed in order to display one player properties to others?
Here's the code:
Setting Player Properties
public void SetBookmarkData()
{
_BookmarkData[1] = inputTextField.text;
PhotonNetwork.LocalPlayer.CustomProperties = _BookmarkData;
}
Displaying Player Properties
public void OnClickUpdate()
{
Debug.Log("Property: " + PhotonNetwork.LocalPlayer.CustomProperties[1]);
text_bookarmarkText.text = PhotonNetwork.LocalPlayer.CustomProperties[1].ToString();
}
This works locally only, I want others to see this properties on other clients as well.
Thanks in advance.
Hi,
you need set player properties using this call:
https://doc-api.photonengine.com/en/pun/v2/class_photon_1_1_realtime_1_1_player.html#a73265fc7665581640574dc7e98526c77
OnClickUpdate needs to be called from the pun callback that will inform you about custom property changes:
https://doc-api.photonengine.com/en/pun/v2/interface_photon_1_1_realtime_1_1_i_in_room_callbacks.html#aabe61c5573a351d1abccb7059d252316
Bye,
Jean
@Sikandar wrote: »
Update
So far I have been able to display custom player properties but these are displayed locally only not sent on server, is there a setting that needs to be changed in order to display one player properties to others?
Here's the code:Setting Player Properties
public void SetBookmarkData() { _BookmarkData[1] = inputTextField.text; PhotonNetwork.LocalPlayer.CustomProperties = _BookmarkData; }
Displaying Player Properties
public void OnClickUpdate() { Debug.Log("Property: " + PhotonNetwork.LocalPlayer.CustomProperties[1]); text_bookarmarkText.text = PhotonNetwork.LocalPlayer.CustomProperties[1].ToString(); }
This works locally only, I want others to see this properties on other clients as well.
Thanks in advance.
Hi Jean,
I am already setting properties with the SetCustomProperties.
Retrieving those properties is an issue which I don't understand how can I get them and show in a text object or console.
This code also doesn't return anything:
public override void OnPlayerPropertiesUpdate(Player targetPlayer, ExitGames.Client.Photon.Hashtable changedProps)
{
base.OnPlayerPropertiesUpdate(targetPlayer, changedProps);
if (changedProps.ContainsKey("1"))
{
text_bookarmarkText.text = "Target Player: " + targetPlayer.CustomProperties;
}
}
HI,
you can read and display every room and player property by using this
Property View
https://github.com/SradnickDev/Photon-Misc/tree/master/Assets/Utilities/Debug/
Its just a debug tool.
I also got something to simplify the work with Room and Player Properties.
https://github.com/SradnickDev/Photon-Misc/blob/master/Assets/Utilities/PropertyHelper.cs
Player Extension
https://github.com/SradnickDev/Photon-Misc/blob/master/Assets/Utilities/PlayerExt.cs
Room Extension
https://github.com/SradnickDev/Photon-Misc/blob/master/Assets/Utilities/RoomExt.cs
//Player example
var currentScore = PhotonNetwork.localPlayer.GetScore();
//Room example
var availableTeam = PhotonNetwork.currentRoom.GetTeams();
@Sikandar wrote: »
This code also doesn't return anything:
public override void OnPlayerPropertiesUpdate(Player targetPlayer, ExitGames.Client.Photon.Hashtable changedProps) { base.OnPlayerPropertiesUpdate(targetPlayer, changedProps); if (changedProps.ContainsKey("1")) { text_bookarmarkText.text = "Target Player: " + targetPlayer.CustomProperties; } }
This function is not supposed to return anything, you use that function to be made aware that changedProps set of values were changed, it's a callback. implement that callback in your pun mono behavior and it will be called everytime a property changed.
don't overthink this, it's straight forward :)
Bye,
Jean
Back to top