android - Unity Google Play Services Plugin API 与 Show Leaderboard UI 功能不同步?

标签 android unity3d google-play-services google-play-games

我使用 Google Play 游戏服务 Unity 插件构建 Android 游戏,如下所述: https://github.com/playgameservices/play-games-plugin-for-unity

问题:

当我使用 API(Google Play 插件的社交 API 或 PlayGamesPlatform.Instance 对象)加载分数时,我得到过时分数。但是,当我改用 ShowLeaderBoardUI() 函数时,GUI 中的分数是正确的。

因此发布分数没有问题。

我使用以下代码 fragment 从 Google Play 游戏服务记分牌加载用户分数:

void LoadUsersAndDisplay(int leaderBoardID,ILeaderboard lb,LeaderBoardEntry[] resultingEntries)
    {
        // get the user ids
        List<string> userIds = new List<string>();

        foreach(IScore score in lb.scores) {
            userIds.Add(score.userID);
        }
        // load the profiles and display (or in this case, log)
        PlayGamesPlatform.Instance.LoadUsers(userIds.ToArray(), (users) =>
            {
                string status = "Leaderboard loading: " + lb.title + " count = " +
                    lb.scores.Length;
                int currentUserIndex = 0;
                foreach(IScore score in lb.scores) {
                    IUserProfile user = users[currentUserIndex];


                    status += "\n" + score.formattedValue + " by " +
                        (string)(
                            (user != null) ? user.userName : "**unk_" + score.userID + "**");

                    resultingEntries[currentUserIndex] = new LeaderBoardEntry(score.rank,user.userName,score.value);
                    currentUserIndex++; 
                }

                // Get the local user score
                LeaderBoardEntry localUserEntry = new LeaderBoardEntry(lb.localUserScore.rank, Social.localUser.userName,lb.localUserScore.value);

                // Notify the observers about the receiving of the scores
                foreach (LeaderBoardObserver currentObserver in observers) {
                    Debug.Log ("Notifying the leaderboard observer");
                    currentObserver.OnScoresReceived (leaderBoardID,resultingEntries,localUserEntry);
                }

                Debug.Log(status);
            });
    }


public void getScores(int lbID){

        ILeaderboard lb = PlayGamesPlatform.Instance.CreateLeaderboard();
        lb.id = leaderboards [lbID].lbOfficialID;
        lb.timeScope = TimeScope.AllTime;
        lb.userScope = UserScope.Global;
        LeaderBoardEntry[] resultingEntries = null;

        lb.LoadScores(ok =>
            {
                if (ok) {
                    resultingEntries = new LeaderBoardEntry[lb.scores.Length];
                    LoadUsersAndDisplay(lbID,lb,resultingEntries);
                }
                else {
                    Debug.Log("Error retrieving leaderboardi");
                }
            });


        Debug.Log ("Have " + observers.Count + " lbObservers");
    }

当我打印收到的排行榜时,我有以下输出:

>>Leaderboard loading: Quick Reaction Mode World Ranking count = 1
>>I/Unity   (16088): 45 by firatercis

但是当我显示全局用户的所有时间分数时,我有以下屏幕截图:

enter image description here

首先,记分牌是空的,我得了45分。我看到双方的45点都没有问题。 然后我打了50分。但是我通过API实现的结果一直没有更新。

我删除并重新安装了游戏,没有。 我清理了应用程序的缓存,任何地方都不应该有任何数字45的副本,但我使用API​​不断获得45分。请帮忙,我可能哪里错了?

最佳答案

我通过更改 LeaderboardManager.LoadLeaderboardData() 解决了这个问题使用 Types.DataSource.NETWORK_ONLY 与 CACHE_OR_NETWORK。

关于android - Unity Google Play Services Plugin API 与 Show Leaderboard UI 功能不同步?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40828345/

相关文章:

unity3d - 为什么 Unity 在构建中包含编辑器目录

c# - 如何在一段时间后隐藏 UI 对象(Video Player)(Unity)

android - ANDY 错误无法启动 VM 进程

android - 如何在 android 中搜索 sdcard 中的图像?

android - 如何使用 ffmpeg 命令在 android 中的 .avi 视频中添加文本标题

c# - 序列化异常 : Could not find type 'System.Collections.Generic.List` 1 in c# unity3d

java - 为什么 startActivityForResult() 方法在这种情况下不起作用

android - 如何使用 Android Studio 3.3 修复即时应用程序

android - LocationServices.FusedLocationApi.requestLocationUpdates onLocationChanged 没有被回调

java - 谷歌 LVL(许可证验证库): is it possible to run the app on a device without Google Play?