fer*_*cis 12 android unity-game-engine google-play-services google-play-games
我使用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");
}
Run Code Online (Sandbox Code Playgroud)
打印收到的排行榜时,我有以下输出:
>>Leaderboard loading: Quick Reaction Mode World Ranking count = 1
>>I/Unity (16088): 45 by firatercis
Run Code Online (Sandbox Code Playgroud)
但是,当我为全球用户显示所有时间分数时,我有以下屏幕截图:
首先,记分牌是空的,我得了45分.我看到双方的45分没有问题.然后我得了50分.但是我通过API实现的结果永远不会更新.
我删除并重新安装了游戏,不.我清理了应用程序的缓存,不应该有任何数字45的副本,但我通过使用API不断得到45分.请帮忙,哪里可能是我的错?
确保 Google Play 开发者控制台上的排行榜设置符合您的预期。特别是,确保排序确实设置为“越大越好”并且您没有设置任何限制。也许切换“启用篡改保护”也是一个好主意......
我本来可以将其写为评论并要求一些澄清,但我没有声誉点。:(
归档时间: |
|
查看次数: |
971 次 |
最近记录: |