我使用Google Play游戏服务Unity插件来构建Android游戏,如下所述: https://github.com/playgameservices/play-games-plugin-for-unity
问题:
当我使用API(Google Play Play插件的社交API或PlayGamesPlatform.Instance对象)加载分数时,我得到过时分数。但是,当我使用ShowLeaderBoardUI()函数时,GUI中的分数是正确的。
所以发布分数没有问题。
我使用以下代码段从Google Play游戏服务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
但是,当我显示全球用户的所有时间分数时,我有以下屏幕截图:
首先,记分牌是空的,我得了45分。我看到双方的45分没有问题。 然后我得了50分。但是我通过API实现的结果永远不会更新。我删除并重新安装了游戏,不。 我清理了应用程序的缓存,不应该有任何数字45的副本,但我通过使用API不断得到45分。请帮忙,我可能在哪里错?
答案 0 :(得分:1)
您的配置可能未完成,如文档中所示:
在Google Play开发者控制台中为您的游戏添加成就和排行榜。对于您配置的每个成就和排行榜,请务必记下相应的成就ID或排行榜ID,因为在进行API调用时将需要这些ID。成就和排行榜ID是字母数字字符串(例如“Cgkx9eiuwi8_AQ”)。
请重新检查您的代码..
答案 1 :(得分:0)
我通过更改LeaderboardManager.LoadLeaderboardData()解决了这个问题,以使用Types.DataSource.NETWORK_ONLY与CACHE_OR_NETWORK。
答案 2 :(得分:-1)
确保Google Play开发者控制台上排行榜的设置符合您的预期。特别是,确保订购确实设置为“更大更好”,并且您没有任何限制设置。也许切换“启用篡改保护”也是一个好主意......
我会把它写成评论并要求澄清,但我没有声望点。 :(