2017-08-31 82 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"); 
    } 
} 
相關問題