首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用google play游戏检索玩家排名

使用google play游戏检索玩家排名
EN

Stack Overflow用户
提问于 2018-06-04 00:33:22
回答 1查看 1.7K关注 0票数 2

我想知道是否有可能在排行榜数据中检索实际玩家的排名?

我想为自定义排行榜UI做这件事。

我用的是unity和google play游戏

EN

回答 1

Stack Overflow用户

发布于 2018-06-04 02:19:30

不确定如何获得排名与official谷歌游戏软件开发工具包,如果这是你正在使用。

使用Unity的Social应用程序接口,您可以通过IScore.rank获取玩家的排名。首先,用给出IScore数组的Social.LoadScores加载分数。循环遍历它并比较IScore.userID,直到找到想要获得其排名的用户id,然后获得IScore.rank

代码语言:javascript
复制
void GetUserRank(string user, Action<int> rank)
{
    Social.LoadScores("Leaderboard01", scores =>
    {
        if (scores.Length > 0)
        {
            Debug.Log("Retrieved " + scores.Length + " scores");

            //Filter the score with the user name
            for (int i = 0; i < scores.Length; i++)
            {
                if (user == scores[i].userID)
                {
                    rank(scores[i].rank);
                    break;
                }
            }
        }
        else
            Debug.Log("Failed to retrieved score");
    });
}

使用

代码语言:javascript
复制
int rank = 0;
GetUserRank("John", (status) => { rank = status; });
Debug.Log("John's rank is: " + rank);

代码语言:javascript
复制
string id = Social.localUser.id;
//string id = PlayGamesPlatform.Instance.localUser.id;
int rank = 0;
GetUserRank(id, (status) => { rank = status; });
Debug.Log(id + "'s rank is: " + rank);

当然,你需要做一些身份验证的事情,因为你可以做到这一点。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50668584

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档