コード例 #1
0
    /*
     *  sample Node =>   RoomHashtable
     *                      playerHashtable
     *                      playerindexHashtable
     */
    public void UpdatePlayerInroom()
    {
        ClearData();
        Debug.Log("Updatepayerinroom ");
        //get playerIndex data
        Hashtable roomPropertyData     = new Hashtable();
        Hashtable playerIndexHashTable = PhotonNetwork.CurrentRoom.CustomProperties[RoomPropertyKeys.PLAYER_INDEX] as Hashtable;

        if (playerIndexHashTable == null)
        {
            playerIndexHashTable = new Hashtable();
        }

        var index       = 0;
        var playerIndex = PhotonNetwork.CurrentRoom.Players.OrderBy(key => key.Key).ToDictionary(k => k.Key, v => v.Value);

        foreach (var item in PhotonNetwork.CurrentRoom.Players)
        {
            Debug.Log(string.Format("Player {0} vale {1} id {2}", item.Key, item.Value, item.Value.UserId));
        }
        foreach (var player in playerIndex)
        {
            Debug.Log("Index " + index);
            Debug.Log("player value " + player.Value);
            Debug.Log("playersData data " + playersData);
            Debug.Log("playersData data count" + playersData.Length);
            playersData[index].SetData(player.Value, playerColor[index]);
            playersData[index].gameObject.SetActive(true);
            PlayerIndexProfileData playerIndexProfileData;
            if (!playerIndexHashTable.ContainsKey(player.Value.UserId))
            {
                var playerProfileJson = player.Value.CustomProperties[PlayerPropertiesKey.PLAYFAB_PROFILE] as string;
                Debug.Log("playerProfileJson " + playerProfileJson);
                Debug.Assert(!string.IsNullOrEmpty(playerProfileJson));
                playerIndexProfileData = new PlayerIndexProfileData {
                    index        = index,
                    nickName     = player.Value.NickName,
                    profileModel = playerProfileJson,
                    userId       = player.Value.UserId,
                    nation       = "thai",
                    colorCode    = ColorUtility.ToHtmlStringRGBA(playerColor[index])
                };
                playerIndexHashTable.Add(player.Value.UserId, playerProfileJson);
            }
            else
            {
                var profileJson = playerIndexHashTable[player.Value.UserId] as string;
                playerIndexProfileData = JsonConvert.DeserializeObject <PlayerIndexProfileData>(profileJson);
            }
            playerIndexProfileData.index              = index;
            playerIndexProfileData.colorCode          = ColorUtility.ToHtmlStringRGBA(playerColor[index]);
            playerIndexHashTable[player.Value.UserId] = JsonConvert.SerializeObject(playerIndexProfileData);
            GameUtil.SetHashTableProperty(roomPropertyData, RoomPropertyKeys.PLAYER_INDEX, playerIndexHashTable);
            index++;
        }
        PhotonNetwork.CurrentRoom.SetCustomProperties(roomPropertyData);
        b_playGame.gameObject.SetActive(PhotonNetwork.CurrentRoom.masterClientId == PhotonNetwork.LocalPlayer.ActorNumber);
    }
コード例 #2
0
    public void SetUp(PlayerIndexProfileData _data)
    {
        profileData = _data;
        Debug.Assert(!string.IsNullOrEmpty(profileData.profileModel));
        profileModel         = GameUtil.ConvertToPlayFabPlayerProfilemodel(profileData.profileModel);
        player_name_txt.text = profileModel.DisplayName;
        Debug.Log(player_name_txt.text + "time " + profileData.playerFinishTime);
        var TimeSpan = System.TimeSpan.FromTicks(System.Convert.ToInt64(profileData.playerFinishTime));

        player_time_txt.text = TimeSpan.ToString(@"mm\:ss\:fff");
    }