[英]Photon Networking Unity AllProperties not setting
I started using Photon Networking for Unity and I ran into a problem. 我开始使用Photon Networking for Unity,我遇到了一个问题。 I want to add to the CustomProperties in the player and then I want to debug the result. 我想添加到播放器中的CustomProperties,然后我想调试结果。 However the debug prints "Null". 但是调试打印“Null”。 I do this after the room is created. 我在创建房间后这样做。
The funny thing is in the OnPhotonPlayerPropertiesChanged()
it does print "changed" and only does that when I execute SetPlayerPosition()
. 有趣的是在OnPhotonPlayerPropertiesChanged()
它打印“已更改”,只有当我执行SetPlayerPosition()
。
But if I then check for the key inside the customproperties is doesn't contain it so it does not print "10"? 但是,如果我然后检查customproperties内部的密钥是不包含它所以它不打印“10”?
void Awake()
{
SetPlayerPosition();
}
public override void OnPhotonPlayerPropertiesChanged(object[] playerAndUpdatedProps)
{
Debug.Log("changed");
if (PhotonNetwork.player.CustomProperties.ContainsKey("1"))
{
Debug.Log("it works");
}
}
void SetPlayerPosition()
{
ExitGames.Client.Photon.Hashtable xyzPos = new ExitGames.Client.Photon.Hashtable();
xyzPos.Add(1, "10");
xyzPos.Add(2, "5");
xyzPos.Add(3, "10");
PhotonNetwork.player.SetCustomProperties(xyzPos);
// PhotonNetwork.player.SetCustomProperties(xyzPos, null, true); doesnt work either
}
According to PUN's doc-api you should do this: 根据PUN的doc-api你应该这样做:
void OnPhotonPlayerPropertiesChanged(object[] playerAndUpdatedProps)
{
PhotonPlayer player = playerAndUpdatedProps[0] as PhotonPlayer;
Hashtable props = playerAndUpdatedProps[1] as Hashtable;
Debug.Log(string.Format("Properties {0} updated for player {1}", SupportClass.DictionaryToString(props), player);
if (player.CustomProperties.ContainsKey("1"))
{
Debug.Log("it works 1");
}
if (props.ContainsKey("1"))
{
Debug.Log("it works 2");
}
}
实际上,awnser是键必须是字符串!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.