我想知道是否可以在排行榜数据中检索实际玩家的排名?
我想为自定义排行榜 UI 执行此操作。
我正在使用 unity 和 google play games
最佳答案
不知道如何获得 official 的排名google-play-games SDK(如果您正在使用该 SDK)。
与Unity的Social
API,可以通过IScore.rank
获取玩家的排名。首先,加载 Social.LoadScores
的分数这给你数组 IScore
。循环它并比较 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);
当然,您必须执行一些身份验证操作,因为您可以这样做。
关于c# - 使用 google play games 检索玩家排名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50668584/