C# 光子网络属性未设置

C# 光子网络属性未设置,c#,unity3d,photon,C#,Unity3d,Photon,我开始为Unity使用光子网络,但遇到了一个问题。我想在播放器中添加CustomProperties,然后调试结果。但是,调试打印“Null”。我在创建房间后执行此操作 有趣的是,OnPhotonPlayerPropertiesChanged()它确实会打印“changed”,并且只有在我执行SetPlayerPosition()时才会打印 但是如果我检查customproperties中的键,它不包含它,所以它不会打印“10” 根据法律,你应该这样做: void OnPhotonPlayerP

我开始为Unity使用光子网络,但遇到了一个问题。我想在播放器中添加CustomProperties,然后调试结果。但是,调试打印“Null”。我在创建房间后执行此操作

有趣的是,
OnPhotonPlayerPropertiesChanged()
它确实会打印“changed”,并且只有在我执行
SetPlayerPosition()时才会打印

但是如果我检查customproperties中的键,它不包含它,所以它不会打印“10”

根据法律,你应该这样做:

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");
    }
}

实际上,关键是键必须是字符串

你是什么意思,“如果我检查customproperties中的键是不包含它的,所以它”-什么是“它”?哈希表不包含键,也不包含值。
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");
    }
}