【问题标题】:Unity: How to get the metadata tag of a leaderboard score in Unity?Unity:如何在 Unity 中获取排行榜分数的元数据标签?
【发布时间】:2019-02-24 13:39:53
【问题描述】:

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

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

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

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

也来自官方文档:

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

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】:

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

    首先,您必须为要报告的分数分配一个元数据标签,如下所示:

    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
    
                }
            }
    );
    

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

    【讨论】:

    • 您先生成就了我的一天。谢谢
    猜你喜欢
    • 1970-01-01
    • 2019-03-28
    • 2014-04-04
    • 1970-01-01
    • 1970-01-01
    • 2014-03-22
    • 1970-01-01
    • 1970-01-01
    • 2021-08-11
    相关资源
    最近更新 更多