c# - 使用 google play games 检索玩家排名

标签 c# android unity-game-engine google-play-games rank

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

我想为自定义排行榜 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/

相关文章:

android - 使用媒体播放器播放音频时,Android显示动画

android - 非导出 Activity : launched on emulators; SecurityException on phones

java - AndroidJavaException : java. lang.ClassNotFoundException : com. google.android.gms.ads.MobileAds

c# - Unity2D - 如何在 2D 游戏中围绕圆移动和旋转游戏对象?

c# - 为什么在finally block 中休眠时线程不被中断

android - 将旧版本的 SQLite 数据库复制到较新版本的应用程序时如何避免崩溃

c# - 如何修复 'file is in use by another process' 错误

unity-game-engine - 当同一对象的 2 个实例发生碰撞时,如何仅销毁 1 个对象?

c# - 对 Viewmodel 进行单元测试

c# - WebMethod 未被调用