作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我开始使用 Photon Networking for Unity,但遇到了一个问题。我想添加到播放器中的 CustomProperties,然后我想调试结果。但是调试打印“Null”。我在创建房间后执行此操作。
有趣的是在 OnPhotonPlayerPropertiesChanged()
中,它确实打印“已更改”并且仅在我执行 SetPlayerPosition()
时才打印。
但是如果我随后检查 customproperties 中的 key 是否不包含它,那么它不会打印“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
}
最佳答案
根据 PUN's 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");
}
}
关于c# - Photon Networking Unity AllProperties 未设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45979173/
我开始使用 Photon Networking for Unity,但遇到了一个问题。我想添加到播放器中的 CustomProperties,然后我想调试结果。但是调试打印“Null”。我在创建房间后
我是一名优秀的程序员,十分优秀!