Unity - Google Play 服务排行榜获取用户排名的问题

问题描述

我在使用 Google Play 服务排行榜时遇到了问题,而且我已经卡了好几天了。

我正在使用 Play Games Plugin for Unity

我正在尝试获取特定级别的用户等级。因此,我通过 Loadscores 函数加载分数,这似乎工作正常。

问题似乎是,我在“Loadscores”函数中获得了正确的排名,但整体 GetUserRank 函数仍然返回 rank = 0,无论实际 Userrank 是多少。

我的猜测是,这毕竟是一个时间问题,并且在 Loadscores 函数计算出要返回的正确排名之前返回排名。

public int GetUserRank(string levelID)
{
    int rank = 0;
    string user = PlayGamesPlatform.Instance.localUser.id;
    string leaderboard = Returnleaderboard(levelID);
    Social.Loadscores(leaderboard,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;
                    // This prints out the actual rank of the user and seems to work
                    print("Rank in LoadscoresFunction: " + rank);
                    break;
                }
            }
        }
        else
            Debug.Log("Failed to retrieved score");
    });
    //Here the rank is always 0,no matter the outcome of the Loadscores Function above
    print("Rank in PlayGamesController: " + rank);
    return rank;
}

我通过以下方式从其他脚本中引用此函数

int rank = PlayGamesController.Instance.GetUserRank(levelID);

非常感谢任何想法/提示

谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)