/// <summary>
        /// 初期化する。
        /// </summary>
        /// <param name="user"></param>
        public void Initialize(RankingUser user)
        {
            _positionText.text = user.Position.ToString();

            _userNameText.text  = user.Name;
            _userLevelText.text = $"Lv.{user.Level}";

            var character = TitleDataManager.CharacterMaster[user.CharacterId];

            _characterName.text    = character.Name;
            _characterLevel.text   = $"Lv.{user.CharacterLevel}";
            _characterImage.sprite = _controller.CharacterSprites[user.CharacterId];
        }
Beispiel #2
0
        public static RankingUser CreateFromPlayerLeaderboardEntry(PlayerLeaderboardEntry entry)
        {
            var friendUser = new RankingUser
            {
                PlayFabId         = entry.PlayFabId,
                Name              = entry.DisplayName,
                Position          = entry.Position + 1, // ポジションは順位を表すが 0 始まりなので +1 しておく
                StatValue         = entry.StatValue,
                Level             = entry.Profile.Statistics?.FirstOrDefault(x => x.Name == "Level")?.Value ?? 1,
                LastLoginDateTime = entry.Profile.LastLogin ?? DateTime.Now,
                CharacterId       = $"character-{string.Format("{0:D8}", entry.Profile.Statistics?.FirstOrDefault(x => x.Name == "CharacterId")?.Value ?? 1)}",
                CharacterLevel    = entry.Profile.Statistics?.FirstOrDefault(x => x.Name == "CharacterLevel")?.Value ?? 1
            };

            return(friendUser);
        }
        /// <summary>
        /// PlayFab からランキングデータを取得する。
        /// </summary>
        /// <returns></returns>
        public static async UniTask SyncPlayFabToClientAsync()
        {
            var request = new GetLeaderboardRequest
            {
                StatisticName      = "Level",
                ProfileConstraints = new PlayerProfileViewConstraints
                {
                    ShowDisplayName = true,
                    ShowStatistics  = true
                }
            };

            var response = await PlayFabClientAPI.GetLeaderboardAsync(request);

            if (response.Error != null)
            {
                throw new PlayFabErrorException(response.Error);
            }

            UserLevelRanking = response.Result.Leaderboard.Select(x => RankingUser.CreateFromPlayerLeaderboardEntry(x)).ToArray();
        }