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

问题描述 投票:0回答:1

我一直在寻找这个,显然谷歌忘记了获取与排行榜得分相关的元数据标签。

在他们的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
               }

});

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

unity3d google-play-services google-play-games
1个回答
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

            }
        }
);

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

© www.soinside.com 2019 - 2024. All rights reserved.