PhotonNetwork.SetPlayerCustomProperties C# (CSharp) Метод

SetPlayerCustomProperties() публичный статический Метод

Sets this (local) player's properties. This caches the properties in PhotonNetwork.player.customProperties. CreateRoom, JoinRoom and JoinRandomRoom will all apply your player's custom properties when you enter the room. While in a room, your properties are synced with the other players. If the Hashtable is null, the custom properties will be cleared. Custom properties are never cleared automatically, so they carry over to the next room, if you don't change them.
Don't set properties by modifying PhotonNetwork.player.customProperties!
public static SetPlayerCustomProperties ( Hashtable customProperties ) : void
customProperties Hashtable Only string-typed keys will be used from this hashtable. If null, custom properties are all deleted.
Результат void
    public static void SetPlayerCustomProperties(Hashtable customProperties)
    {
        if (customProperties == null)
        {
            customProperties = new Hashtable();
            foreach (object k in player.customProperties.Keys)
            {
                customProperties[(string)k] = null;
            }
        }

        if (room != null && room.isLocalClientInside)
        {
            player.SetCustomProperties(customProperties);
        }
        else
        {
            player.InternalCacheProperties(customProperties);
        }
    }

Usage Example

Пример #1
0
    void OnJoinedRoom()
    {
        int blueCount = 0;
        int redCount  = 0;

        foreach (PhotonPlayer player in PhotonNetwork.playerList)
        {
            if (!player.Equals(PhotonNetwork.player))
            {
                if ((bool)player.CustomProperties["isBlue"])
                {
                    blueCount++;
                }
                else
                {
                    redCount++;
                }
            }
        }
        ExitGames.Client.Photon.Hashtable props = new ExitGames.Client.Photon.Hashtable();
        props.Add("isBlue", redCount >= blueCount);

        PhotonNetwork.SetPlayerCustomProperties(props);
        if (PlayerPrefs.GetString("DisplayName") == "")
        {
            int ranNum = (int)Mathf.Floor(Random.value * 1000);
            PlayerPrefs.SetString("DisplayName", "Player" + ranNum);
            PlayerPrefs.Save();
        }
        PhotonNetwork.playerName = PlayerPrefs.GetString("DisplayName");
        gameObject.SetActive(false);
        roomWait.SetActive(true);
        roomWait.GetComponent <PhotonView>().RPC("ChangeNames", PhotonTargets.All);
    }
All Usage Examples Of PhotonNetwork::SetPlayerCustomProperties