簡體   English   中英

光子網絡Unity AllProperties沒有設置

[英]Photon Networking Unity AllProperties not setting

我開始使用Photon Networking for Unity,我遇到了一個問題。 我想添加到播放器中的CustomProperties,然后我想調試結果。 但是調試打印“Null”。 我在創建房間后這樣做。

有趣的是在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
    }

根據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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM