/// <summary>
    /// Updates the value of a given PlayFab statistic.
    /// </summary>
    /// <param name="statisticName">Name of the PlayFab statistic to be updated.</param>
    /// <param name="value">Value the statistic must receive.</param>
    /// <param name="successCallback">Action to be executed when the process is done correctly.</param>
    public void UpdateStat(string statisticName, int value, Action <UpdatePlayerStatisticsResult> successCallback = null)
    {
        if (!IsLoggedOnPlayFab)
        {
            Debug.LogError("EasyLeaderboard.UpdateStat => Not logged on PlayFab!");
            return;
        }

        var request = new UpdatePlayerStatisticsRequest
        {
            Statistics = new List <StatisticUpdate>
            {
                new StatisticUpdate
                {
                    StatisticName = statisticName,
                    Value         = value
                }
            }
        };

        successCallback += (result) =>
        {
            Debug.Log(string.Format("EasyLeaderboard.UpdateStat => Success! (Statistic '{0}', value {1})",
                                    statisticName, value));
        };

        PlayFabClientAPI.UpdatePlayerStatistics(request, successCallback, PlayFabErrorCallback);
    }
Exemplo n.º 2
0
        private void GetPlayerStatsCallback1(GetPlayerStatisticsResult result)
        {
            var testContext = (UUnitTestContext)result.CustomData;

            _testInteger = 0;
            foreach (var eachStat in result.Statistics)
            {
                if (eachStat.StatisticName == TEST_STAT_NAME)
                {
                    _testInteger = eachStat.Value;
                }
            }
            _testInteger = (_testInteger + 1) % 100; // This test is about the Expected value changing - but not testing more complicated issues like bounds

            var updateRequest = new UpdatePlayerStatisticsRequest
            {
                Statistics = new List <StatisticUpdate>
                {
                    new StatisticUpdate {
                        StatisticName = TEST_STAT_NAME, Value = _testInteger
                    }
                }
            };

            clientInstance.UpdatePlayerStatistics(updateRequest, PlayFabUUnitUtils.ApiActionWrapper <UpdatePlayerStatisticsResult>(testContext, UpdatePlayerStatsCallback), PlayFabUUnitUtils.ApiActionWrapper <PlayFabError>(testContext, SharedErrorCallback), testContext);
        }
Exemplo n.º 3
0
    public void SubmitScore(int scoreValue, UnityAction <bool> callback = null)
    {
        var update = new StatisticUpdate {
            StatisticName = Globals.PLAYFAB_SCORE_KEY,
            Value         = scoreValue
        };
        var list = new List <StatisticUpdate>();

        list.Add(update);
        var req = new UpdatePlayerStatisticsRequest();

        req.Statistics = list;
        PlayFabClientAPI.UpdatePlayerStatistics(req, result => {
            if (callback != null)
            {
                callback(true);
            }
        }, failure => {
            OnNetworkOperationFailure(failure);
            if (callback != null)
            {
                callback(false);
            }
        });
    }
Exemplo n.º 4
0
    /// <summary>
    /// 統計情報を更新する
    /// </summary>
    /// <param name="rankingName">ランキング名</param>
    /// <param name="value">更新する値</param>
    public void UpdatePlayerStatistics(string rankingName, int value)
    {
        // Playfabにログイン済みかを確認する
        if (PlayFabClientAPI.IsClientLoggedIn())
        {
            // 通信待ちでなかったら通信開始
            if (!waitConnect.GetWait(gameObject.name))
            {
                // 通信待ちに設定する
                waitConnect.AddWait(gameObject.name);

                // UpdatePlayerStatisticsRequestのインスタンスを生成
                var request = new UpdatePlayerStatisticsRequest
                {
                    Statistics = new List <StatisticUpdate> {
                        new StatisticUpdate {
                            StatisticName = rankingName, //ランキング名(統計情報名)
                            Value         = value,       // スコア(int)
                        }
                    }
                };
                Debug.Log($"統計情報名:" + rankingName + " Value:" + value);

                // スコア情報の更新
                Debug.Log($"スコア(統計情報)の更新開始");
                PlayFabClientAPI.UpdatePlayerStatistics(request,
                                                        OnUpdatePlayerStatisticsSuccess,
                                                        OnUpdatePlayerStatisticsFailure);
            }
        }
        else
        {
            Debug.Log("統計情報設定に失敗:PlayFabに未ログイン");
        }
    }
Exemplo n.º 5
0
    public void StorePlayerStats(bool updateLVL, bool updateQP, bool updateRank, bool updateTR)
    {
        if (DataLoaded)
        {
            List <StatisticUpdate>        stats   = new List <StatisticUpdate>();
            UpdatePlayerStatisticsRequest request = new UpdatePlayerStatisticsRequest();
            DataSaveing = true;

            if (updateLVL)
            {
                addStat(stats, "Level", localPlayerData.level);
                addStat(stats, "exp", localPlayerData.exp);
            }
            if (updateQP)
            {
                addStat(stats, "qp_wins", localPlayerData.qp_wins);
                addStat(stats, "qp_losses", localPlayerData.qp_losses);
            }
            if (updateRank)
            {
                addStat(stats, "Rang", localPlayerData.rank);
                addStat(stats, "Wins", localPlayerData.wins);
                addStat(stats, "Looses", localPlayerData.looses);
            }
            if (updateTR)
            {
                addStat(stats, "tr_wins", localPlayerData.tr_wins);
                addStat(stats, "tr_losses", localPlayerData.tr_losses);
            }

            request.Statistics = stats;
            PlayFabClientAPI.UpdatePlayerStatistics(request, StatsUpdated, OnPlayFabError);
        }
    }
Exemplo n.º 6
0
    public void SendLeaderboard(int score)
    {
        var request = new UpdatePlayerStatisticsRequest
        {
            Statistics = new List <StatisticUpdate>
            {
                new StatisticUpdate
                {
                    StatisticName = "Daily Score",
                    Value         = score
                },
                new StatisticUpdate
                {
                    StatisticName = "Monthly Score",
                    Value         = score
                },
                new StatisticUpdate
                {
                    StatisticName = "Scores",
                    Value         = score
                }
            }
        };

        PlayFabClientAPI.UpdatePlayerStatistics(request, OnLeaderboardUpdate, OnError);
    }
Exemplo n.º 7
0
    public void UpdatePlayerLevelsLeaderoard(int level)
    {
        if (PlayFabClientAPI.IsClientLoggedIn())
        {
            if (string.IsNullOrEmpty(_levelsCountLeaderboardId))
            {
                Debug.LogWarning("PlayFabManager: LevelsCountLeaderboardId is not assigned! Please assign it.");
                return;
            }

            if (level > 0)
            {
                var statistic = new StatisticUpdate()
                {
                    StatisticName = _levelsCountLeaderboardId,
                    Value         = level
                };
                List <StatisticUpdate> statistics = new List <StatisticUpdate>();
                statistics.Add(statistic);

                UpdatePlayerStatisticsRequest request = new UpdatePlayerStatisticsRequest()
                {
                    Statistics = statistics
                };

                PlayFabClientAPI.UpdatePlayerStatistics(request, OnPlayersLevelStatisticsUpdated,
                                                        PlayerStatisticUpdateErrorCallback);
            }
        }
    }
Exemplo n.º 8
0
    public void UpdatePlayerStatistic(int value, Action onSuccess, Action onCancel = null)
    {
        var request = new UpdatePlayerStatisticsRequest
        {
            Statistics = new List <StatisticUpdate>()
            {
                new StatisticUpdate {
                    StatisticName = StatisticName,
                    Value         = value
                }
            }
        };

        PlayFabClientAPI.UpdatePlayerStatistics(
            request,
            _result => {
            DebugLogUpdateStatistics(_result);

            onSuccess?.Invoke();
        },
            _error => {
            var report = _error.GenerateErrorReport();
            Debug.LogError(report);

            ErrorDialogView.Show("UpdatePlayerStatistics failed", report, () => {
                UpdatePlayerStatistic(value, onSuccess, onCancel);
            }, onCancel);
        });
    }
Exemplo n.º 9
0
        public void SendRanking(RankKind kind, float time, Action onSent)
        {
            if (!loginManager.IsLoggedIn())
            {
                loginManager.Login(() => SendRanking(kind, time, onSent), error => print(error.GenerateErrorReport()));
                return;
            }

            int score = TimeToNumberForPlayFab(time);
            List <StatisticUpdate> stats = new List <StatisticUpdate>();

            stats.Add(new StatisticUpdate {
                StatisticName = kind.ToString(), Value = score
            });
            var request = new UpdatePlayerStatisticsRequest
            {
                Statistics = stats
            };

            PlayFabClientAPI.UpdatePlayerStatistics
            (
                request,
                result => onSent.Invoke(),
                error => Debug.LogError(error.GenerateErrorReport())
            );
        }
Exemplo n.º 10
0
    //更新玩家统计数据 例如杀敌总数 总胜场数
    void SetPlayFabUserStats()
    {
        List <StatisticUpdate> stats = new List <StatisticUpdate>();

        stats.Add(new StatisticUpdate()
        {
            StatisticName = "TotalKill", Value = PlayFabUserData.totalKill
        });
        stats.Add(new StatisticUpdate()
        {
            StatisticName = "KillPerDeath", Value = (int)(PlayFabUserData.killPerDeath * 100)
        });
        stats.Add(new StatisticUpdate()
        {
            StatisticName = "TotalWin", Value = PlayFabUserData.totalWin
        });
        stats.Add(new StatisticUpdate()
        {
            StatisticName = "WinPercentage", Value = (int)(PlayFabUserData.winPercentage * 100)
        });
        UpdatePlayerStatisticsRequest request = new UpdatePlayerStatisticsRequest
        {
            Statistics = stats
        };

        PlayFabClientAPI.UpdatePlayerStatistics(request, (result) => { }, (error) => { });
    }
Exemplo n.º 11
0
    void SendScoreRaw(string ID, ScoreCompare playerScore, Action <ScoreCompare[]> onSuccess, Action <PlayFabError> errorAction)
    {
        var item = new StatisticUpdate();

        item.Value         = playerScore.value;
        item.StatisticName = "Worldwide Scores";

        var request = new UpdatePlayerStatisticsRequest();

        request.Statistics = new List <StatisticUpdate>()
        {
            item
        };
        PlayFabClientAPI.UpdatePlayerStatistics(request,
                                                result =>
        {
            var r        = new PlayFab.ServerModels.UpdateUserDataRequest();
            r.Permission = PlayFab.ServerModels.UserDataPermission.Public;
            r.PlayFabId  = uniqueID;
            r.Data       = new Dictionary <string, string>()
            {
                { "SkinID", ((int)playerScore.usedSkin).ToString() },
                { "Location", playerScore.location }
            };

            PlayFabServerAPI.UpdateUserData(r, sucess => GetScores(onSuccess, errorAction),
                                            failure => { Debug.Log("Fail: " + failure.ErrorMessage); });
        },
                                                failure => { });
    }
Exemplo n.º 12
0
    public IEnumerator UpdateStat(string name, int value)
    {
        //GameManager.SetDebugOutput("stats", "stat updates disabled");
        //yield break;

        // Don't spam if client is not logged in (offline). Some score might also be posted before login completes and the SDK throws then.
        if (!PlayFabClientAPI.IsClientLoggedIn())
        {
            yield break;
        }

        UpdatePlayerStatisticsRequest req = new UpdatePlayerStatisticsRequest();
        StatisticUpdate stat = new StatisticUpdate
        {
            Version       = stats.ContainsKey(name) ? (uint?)stats[name].Version : null,
            StatisticName = name,
            Value         = value,
        };

        req.Statistics = new List <StatisticUpdate> {
            stat
        };

        Action <Action <UpdatePlayerStatisticsResult>, Action <PlayFabError> > apiCall = (onsuccess, onError) =>
        {
            PlayFabClientAPI.UpdatePlayerStatistics(req, onsuccess, onError);
        };

        yield return(ExecuteApiCallWithRetry(apiCall, busyIndicatorAfterSec: 0.0f, messageBoxAfterSec: 4.0f));
    }
Exemplo n.º 13
0
        public static async Task <dynamic> MakeApiCall(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, ILogger log)
        {
            /* Create the function execution's context through the request */
            var context = await FunctionContext <dynamic> .Create(req);

            var args = context.FunctionArgument;

            /* Create the request object through the SDK models */
            var request = new UpdatePlayerStatisticsRequest
            {
                PlayFabId  = context.CurrentPlayerId,
                Statistics = new List <StatisticUpdate>
                {
                    new StatisticUpdate
                    {
                        StatisticName = "Level",
                        Value         = 2
                    }
                }
            };
            /* Use the ApiSettings and AuthenticationContext provided to the function as context for making API calls. */
            var serverApi = new PlayFabServerInstanceAPI(context.ApiSettings, context.AuthenticationContext);

            /* The PlayFabServerAPI SDK methods provide means of making HTTP request to the PlayFab Main Server without any
             * extra code needed to issue the HTTP requests. */
            return(await serverApi.UpdatePlayerStatisticsAsync(request));
        }
Exemplo n.º 14
0
    public void UpdatePlayerLevelScoresLeaderboard(int level, int score)
    {
        if (PlayFabClientAPI.IsClientLoggedIn())
        {
            if (string.IsNullOrEmpty(_levelScoresLeaderboardId))
            {
                Debug.LogWarning("PlayFabManager: LevelScoresLeaderboardId is not assigned!Please assign it.");
                return;
            }

            if (level > 0 && score > 0)
            {
                string statisticName = string.Format(_levelScoresLeaderboardId, level);

                var statistic = new StatisticUpdate()
                {
                    StatisticName = statisticName,
                    Value         = score
                };
                List <StatisticUpdate> statistics = new List <StatisticUpdate>();
                statistics.Add(statistic);

                UpdatePlayerStatisticsRequest request = new UpdatePlayerStatisticsRequest()
                {
                    Statistics = statistics
                };

                PlayFabClientAPI.UpdatePlayerStatistics(request, OnPlayerLevelScoresStatisticsUpdatedResultCallback,
                                                        PlayerStatisticUpdateErrorCallback);
            }
        }
    }
Exemplo n.º 15
0
    // playfab에 IDInfo 저장
    void SetStat()
    {
        var request = new UpdatePlayerStatisticsRequest {
            Statistics = new List <StatisticUpdate> {
                new StatisticUpdate {
                    StatisticName = "IDInfo", Value = 0
                }
            }
        };

        PlayFabClientAPI.UpdatePlayerStatistics(request, (result) => { }, (error) => Debug.Log("아,, 값 저장실패"));
    }
Exemplo n.º 16
0
    public void SendLeaderBoard(int startTimeconverted)       //Send time recorded to database when finish line is crossed
    {
        var request = new UpdatePlayerStatisticsRequest {
            Statistics = new List <StatisticUpdate> {
                new StatisticUpdate {
                    StatisticName = "TimeScores", Value = startTimeconverted
                }
            }
        };

        PlayFabClientAPI.UpdatePlayerStatistics(request, OnLeaderboardUpdate, OnLoginFailure);
    }
    public void SendDataToLeaderboard(int score)
    {
        var request = new UpdatePlayerStatisticsRequest {
            Statistics = new List <StatisticUpdate> {
                new StatisticUpdate {
                    StatisticName = "LapTimeScore",
                    Value         = score
                }
            }
        };

        PlayFabClientAPI.UpdatePlayerStatistics(request, OnLeaderboardUpdate, OnError);
    }
Exemplo n.º 18
0
    public void SendLeaderboard(int stage)
    {
        var request = new UpdatePlayerStatisticsRequest {
            Statistics = new List <StatisticUpdate> {
                new StatisticUpdate {
                    StatisticName = "Highest Stage",
                    Value         = stage
                }
            }
        };

        PlayFabClientAPI.UpdatePlayerStatistics(request, OnLeaderboardUpdate, OnError);
    }
Exemplo n.º 19
0
    void SendScore(int score, string name)
    {
        if (!PlayFabClientAPI.IsClientLoggedIn())
        {
            Login(() => SendScore(score, name));
            return;
        }

        UpdatePlayerStatisticsRequest request = new UpdatePlayerStatisticsRequest()
        {
            Statistics = new List <StatisticUpdate>()
            {
                new StatisticUpdate()
                {
                    StatisticName = "totalScore",
                    Value         = score
                }
            }
        };

        PlayFabClientAPI.UpdatePlayerStatistics
        (
            request,
            result =>
        {
            var below = rankUnits.FirstOrDefault(unit => unit.Score <= score);
            int index = (below is null) ? rankUnits.Count : below.transform.GetSiblingIndex();
            if (myUnit is null)
            {
                myUnit = Instantiate(rankUnitPrefab, rankContentsParent);
                myUnit.Init(index + 1, name, score);
                rankUnits.Skip(index).ForEach(unit => unit.Rank++);
            }
            else
            {
                rankUnits.Remove(myUnit);

                int oldRank = myUnit.Rank;

                myUnit.Rank  = index + 1;
                myUnit.Name  = name;
                myUnit.Score = score;

                rankUnits.Take(oldRank - 1).Skip(index).ForEach(unit => unit.Rank++);
            }
            myUnit.transform.SetSiblingIndex(index);
            rankUnits.Insert(index, myUnit);

            bestScore = score;
            highScore.Set(bestScore);
        },
Exemplo n.º 20
0
        public static async Task <dynamic> LevelCompleted(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, ILogger log)
        {
            /* Create the function execution's context through the request */
            var context = await FunctionContext <dynamic> .Create(req);

            var args = context.FunctionArgument;

            var level          = args["levelName"];
            var monstersKilled = (int)args["monstersKilled"];

            var updateUserInternalDataRequest = new UpdateUserInternalDataRequest
            {
                PlayFabId = context.CurrentPlayerId,
                Data      = new Dictionary <string, string>
                {
                    { "lastLevelCompleted", level }
                }
            };

            /* Use the ApiSettings and AuthenticationContext provided to the function as context for making API calls. */
            var serverApi = new PlayFabServerInstanceAPI(context.ApiSettings, context.AuthenticationContext);
            /* Execute the Server API request */
            var updateUserDataResult = await serverApi.UpdateUserInternalDataAsync(updateUserInternalDataRequest);

            log.LogDebug($"Set lastLevelCompleted for player {context.CurrentPlayerId} to {level}");

            var updateStatRequest = new UpdatePlayerStatisticsRequest
            {
                PlayFabId  = context.CurrentPlayerId,
                Statistics = new List <StatisticUpdate>
                {
                    new StatisticUpdate
                    {
                        StatisticName = "level_monster_kills",
                        Value         = monstersKilled
                    }
                }
            };

            /* Execute the server API request */
            var updateStatResult = await serverApi.UpdatePlayerStatisticsAsync(updateStatRequest);

            log.LogDebug($"Updated level_monster_kills stat for player {context.CurrentPlayerId} to {monstersKilled}");

            return(new
            {
                updateStatResult.Result
            });
        }
Exemplo n.º 21
0
    private void InitStat()
    {
        var request = new UpdatePlayerStatisticsRequest()
        {
            Statistics = new List <StatisticUpdate>
            {
                new StatisticUpdate {
                    StatisticName = "score", Value = 0
                }
            }
        };

        PlayFabClientAPI.UpdatePlayerStatistics(request, InitStatSuccess, IniStatFailed);
    }
    public void SendLeaderboard(int score)
    {
        var request = new UpdatePlayerStatisticsRequest
        {
            Statistics = new List <StatisticUpdate>
            {
                new StatisticUpdate
                {
                    StatisticName = SceneManager.GetActiveScene().name,
                    Value         = score
                }
            }
        };

        PlayFabClientAPI.UpdatePlayerStatistics(request, OnLeaderboardUpdate, OnError);
    }
        public void SendScore(int score)
        {
            var request = new UpdatePlayerStatisticsRequest
            {
                Statistics = new List <StatisticUpdate>
                {
                    new StatisticUpdate
                    {
                        StatisticName = _leaderboardSettings.StatisticName,
                        Value         = score
                    }
                }
            };

            PlayFabClientAPI.UpdatePlayerStatistics(request, OnUpdateSuccess, OnUpdateFailure);
        }
Exemplo n.º 24
0
    public void SendWinStatistic(int newWin)
    {
        var request = new UpdatePlayerStatisticsRequest
        {
            Statistics = new List <StatisticUpdate>
            {
                new StatisticUpdate
                {
                    StatisticName = "MostWin",
                    Value         = newWin
                }
            }
        };

        PlayFabClientAPI.UpdatePlayerStatistics(request, OnWinSent, OnError);
    }
Exemplo n.º 25
0
    public static void UpdatePlayerStatistics(string statistics, int value = 1)
    {
        var request = new UpdatePlayerStatisticsRequest
        {
            // request.Statistics is a list, so multiple StatisticUpdate objects can be defined if required.
            Statistics = new List <StatisticUpdate> {
                new StatisticUpdate {
                    StatisticName = statistics, Value = value
                },
            }
        };

        PlayFabClientAPI.UpdatePlayerStatistics(request,
                                                result => { Debug.Log("User statistics updated"); },
                                                error => { Debug.LogError(error.GenerateErrorReport()); });
    }
Exemplo n.º 26
0
    public void Sendscore()
    {
        var request = new UpdatePlayerStatisticsRequest
        {
            Statistics = new List <StatisticUpdate>
            {
                new StatisticUpdate
                {
                    StatisticName = "Overall Score",
                    Value         = PlayerPrefs.GetInt("TOTALSCORE")
                }
            }
        };

        PlayFabClientAPI.UpdatePlayerStatistics(request, Onsuccessupdate, Onerror);
    }
    public void UpdateStatistics()
    {
        List <StatisticUpdate> stat = new List <StatisticUpdate>();
        StatisticUpdate        item = new StatisticUpdate();

        item.StatisticName = "Kills";
        item.Value         = kills;
        stat.Add(item);

        var request = new UpdatePlayerStatisticsRequest {
            Statistics = stat
        };

        PlayFab.PlayFabClientAPI.UpdatePlayerStatistics(request, StatResult, OnPlayFabError);
        killsOld = kills;
    }
Exemplo n.º 28
0
    public void storeScore()
    {
        List <StatisticUpdate> stats = new List <StatisticUpdate>();
        StatisticUpdate        score = new StatisticUpdate();

        score.StatisticName = "score";
        score.Value         = player_score;

        stats.Add(score);

        UpdatePlayerStatisticsRequest req = new UpdatePlayerStatisticsRequest();

        req.AuthenticationContext = authContext;
        req.Statistics            = stats;

        PlayFabClientAPI.UpdatePlayerStatistics(req, statsSuccessCallback, statsErrorCallback);
    }
Exemplo n.º 29
0
    public void AddScore(Leaderboard board, int score, Action <UpdatePlayerStatisticsResult> cb, Action <PlayFabError> errorCb)
    {
        StatisticUpdate item = new StatisticUpdate
        {
            StatisticName = PlayFabLeaderboard.GetBoardName(board, false),
            Value         = score
        };
        UpdatePlayerStatisticsRequest request = new UpdatePlayerStatisticsRequest
        {
            Statistics = new List <StatisticUpdate>
            {
                item
            }
        };

        PlayFabClientAPI.UpdatePlayerStatistics(request, cb, errorCb, null, null);
    }
Exemplo n.º 30
0
    public void SaveStats()
    {
        // Create new request
        var request = new UpdatePlayerStatisticsRequest();

        // Statistics List
        request.Statistics = new List <StatisticUpdate>();
        // Create new value for statistics
        var stat = new StatisticUpdate {
            StatisticName = "Coins", Value = 5
        };

        // Add entry
        request.Statistics.Add(stat);
        // Send request to PlayfabAPI
        PlayFabClientAPI.UpdatePlayerStatistics(request, OnSetStatsSuccess, OnPlayFabError);
    }