Unity Google Play Services插件API与显示排行榜UI功能不同步?

16

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

问题:

当我使用API(Social API或google play插件的PlayGamesPlatform.Instance对象)加载分数时,我会得到过时的分数。但是,当我使用ShowLeaderBoardUI()函数时,GUI中的分数是正确的。

因此,在发布分数方面没有问题。

我使用以下代码片段从Google Play Game Services ScoreBoard中加载用户分数:

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 分。请帮忙看看,我可能错在哪里了?


1
只有一个想法;正因为这个原因,几乎每个人都只使用Prime31插件来进行GPGS开发。(当然,谷歌自己的软件是个笑话。)不得不支付几美元确实很糟糕,而且仍然很麻烦,但这通常是前进的唯一途径。 - Fattie
谢谢,那是一条有价值的信息。如果我无法解决这个 bug(我已经在处理它两周了),我会将其视为一个选项。 - fercis
每次获得高分时,您应该发布分数。您是否这样做了?您可以使用 Social.ReportScore 进行发布。 - Programmer
1
这比你想象的更头疼 :O prime31团队有一个组合包,意味着一个prime31插件可以在你的IOS构建和ANDROID构建中工作,以连接到GPGS。https://prime31.com/docs#comboPlayGameServices - Fattie
啊哈哈 :D 这个 bug 把我的编程生活变成了一部情景喜剧。Prime31 组合包只能通过 PayPal 购买,而 PayPal 在我的国家不受支持。 - fercis
显示剩余4条评论
3个回答

1

0

确保 Google Play 开发者控制台上排行榜的设置符合您的意图。特别是,请确保排序确实设置为“较大者优先”,并且您没有设置任何限制。也许切换“启用篡改保护”也是一个好主意...

我本来会将此写成评论并请求一些澄清,但我没有足够的声望点数。:(


我将“越大越好”作为排序方式,并且没有限制。我已禁用篡改保护,尽快尝试。感谢评论 :) - fercis
现在我有机会尝试了,但问题仍然存在。 - fercis
啊,抱歉那不是你的问题。如果我想到了别的解决办法,我会告诉你的。 - Alistair Jones
为什么要对这个回答点踩?这是一个有效的回答,只是不是 OP 寻找的答案... - Alistair Jones

0

可能是您的配置未按照文档所示完成:

在Google Play开发者控制台中为您的游戏添加成就和排行榜。对于每个成就和排行榜,确保记下相应的成就ID或排行榜ID,因为在进行API调用时会需要这些。成就和排行榜ID是字母数字字符串(例如"Cgkx9eiuwi8_AQ")。

请重新检查您的代码。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接