상속: PlayFabRequestCommon
예제 #1
0
        //update the score for a given user on the "global" leaderboard
        private static void AssignScore(string fabId, int score)
        {
            var request = new PlayFab.ServerModels.UpdatePlayerStatisticsRequest
            {
                PlayFabId  = fabId,
                Statistics = new List <PlayFab.ServerModels.StatisticUpdate>
                {
                    new PlayFab.ServerModels.StatisticUpdate
                    {
                        StatisticName = "global",
                        Value         = score
                    }
                }
            };
            var result = PlayFabServerAPI.UpdatePlayerStatisticsAsync(request).GetAwaiter().GetResult();

            if (result.Error != null)
            {
                Console.WriteLine(result.Error.ErrorMessage);
            }
        }
    public void UpdatePlayerStatistics(string username, string password)
    {
        var statisticName1 = "Hourly High Score";
        var statisticName2 = "Overall High Score";

        var request = new LoginWithPlayFabRequest {
            Username = username, Password = password
        };

        PlayFabClientAPI.LoginWithPlayFab(request,
                                          delegate(LoginResult loginResult)
        {
            var updatePlayerStatisticsRequest = new UpdatePlayerStatisticsRequest()
            {
                PlayFabId  = loginResult.PlayFabId,
                Statistics = new List <StatisticUpdate>()
                {
                    new StatisticUpdate()
                    {
                        StatisticName = statisticName1, Value = GameController.score
                    },
                    new StatisticUpdate()
                    {
                        StatisticName = statisticName2, Value = GameController.score
                    }
                }
            };

            PlayFabServerAPI.UpdatePlayerStatistics(updatePlayerStatisticsRequest,
                                                    delegate(UpdatePlayerStatisticsResult updatePlayerStatisticsResult)
            {
                Debug.Log("Statistic: " + statisticName1 + " and Statistic: " + statisticName2 + " were updated");
            },
                                                    SharedError.OnSharedError);
        },
                                          SharedError.OnSharedError);
    }