我想知道是否有可能在排行榜数据中检索实际玩家的排名?
我想为自定义排行榜UI做这件事。
我用的是unity和google play游戏
发布于 2018-06-04 02:19:30
不确定如何获得排名与official谷歌游戏软件开发工具包,如果这是你正在使用。
使用Unity的Social应用程序接口,您可以通过IScore.rank获取玩家的排名。首先,用给出IScore数组的Social.LoadScores加载分数。循环遍历它并比较IScore.userID,直到找到想要获得其排名的用户id,然后获得IScore.rank。
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");
});
}使用
int rank = 0;
GetUserRank("John", (status) => { rank = status; });
Debug.Log("John's rank is: " + rank);或
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);当然,你需要做一些身份验证的事情,因为你可以做到这一点。
https://stackoverflow.com/questions/50668584
复制相似问题