2017-08-31 79 views
3

我开始使用Photon Networking for Unity,并遇到了问题。我想添加到播放器的CustomProperties中,然后我想调试结果。但是,调试打印“空”。我在创建房间后这样做。Photon Networking Unity AllProperties not setting

有趣的是在OnPhotonPlayerPropertiesChanged()它打印“改变”,只有当我执行SetPlayerPosition()时。

但是,如果我然后检查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 
    } 
+0

你是什么意思,“如果我然后检查customproperties内部的密钥是不包含它所以它” - 什么是“它”? –

+0

散列表不包含这些键,并且不包含这些值。 –

回答

0

其实awnser是密钥必须是串!

1

根据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"); 
    } 
} 
相关问题