Unity:如何在Unity中获取排行榜得分的元数据标签?

时间:2019-02-24 13:39:53

标签: unity3d google-play-services google-play-games

为此,我一直到处寻找,显然Google忘记了获取与排行榜得分相关联的元数据标签。

在他们的Official Github unity plugin Documentation中,他们明确指出:

  

要发布分数并包括元数据标签,请直接使用Play Game Services实例:

enter image description here

这很好用,,但是现在经过大量搜索之后,我认为您无法从排行榜取回此元数据标签!

也来自官方文档:

您可以使用以下功能从排行榜加载分数:

PlayGamesPlatform.Instance.LoadScores(lId,
            leaderboardStart,
            scoresToDisplay,
            leaderboardType,
            leaderboardTimeSpan,
            (LeaderboardScoreData data) => {
               for (int i = 0; i < data.Scores.Length; i++)
               {
                   IScore score = data.Scores[i];

                   //handle where you want to save the scores
               }

});

任何人都可以帮助获取分数元数据标签吗?

1 个答案:

答案 0 :(得分:0)

我终于想通了,对于任何想要做我想做的事情的人,这就是解决方案:

首先,您必须像这样向要报告的分数分配一个元数据标签:

public void ReportScoreToLeaderboard(string leaderboardId, int score)
{
    PlayGamesPlatform.Instance.ReportScore(score, leaderboardId, "SantaCharacter", (bool success) => {
        // handle success or failure
    });
}

然后,当您想获得带有标签的分数时,只需将 IScore 投射到 PlayGamesScore ,就像这样:

PlayGamesPlatform.Instance.LoadScores(lId,
        leaderboardStart,
        scoresToDisplay,
        leaderboardType,
        leaderboardTimeSpan,
        (LeaderboardScoreData data) => {

            for (int i = 0; i < data.Scores.Length; i++)
            {
                //Just cast the IScore to PlayGamesScore :)
                PlayGamesScore score = (PlayGamesScore) data.Scores[i];

                float scoreValue = score.value;
                string tag = score.metaData;

                //store them and do what you want with them

            }
        }
);

我希望这会帮助某人。