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

Unity: How to get the metadata tag of a leaderboard score in Unity?

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

在他们的Official Github unity plugin Documentation中,他们明确表示:

To post a score and include a metadata tag use the Play Game Services instance directly:

这非常有效,但现在经过大量搜索后,我认为您无法从排行榜中取回此元数据标签!

同样来自官方文档:

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

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
               }

});

任何人都可以帮助了解如何获取乐谱元数据标签吗?

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

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

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

            }
        }
);

我希望这会对某人有所帮助。