问题描述
我正在尝试学习如何在Unity中使用GooglePlayServices,但是我有一个我无法处理的小问题.因此,我可以从排行榜中获取所有信息,并在日志中提示它,但我不能做其他事情.这是我的代码:
I'm trying to learn how to use GooglePlayServices in Unity but i have a little problem that i can't handle.So i can get all information from leaderboard and prompt it in Log but i can't do enything else. Here is my code:
IScore[] scoresFromLeaderboard = null;
PlayGamesPlatform.Instance.LoadScores(
GPGSIds.leaderboard_highscore_leaderboard,
LeaderboardStart.TopScores,
10,
LeaderboardCollection.Public,
LeaderboardTimeSpan.AllTime,
(data) =>
{
scoresFromLeaderboard = data.Scores;
Debug.Log("Scoures count: " + scoresFromLeaderboard.Length);
foreach(IScore score in scoresFromLeaderboard)
{
Debug.Log("Score: " + score.formattedValue);
}
}
);
当我尝试添加变量并为其添加一些分数时,什么也没有发生.另外,当我尝试这样做foreach:
When i try to add variable and write some score to it there's nothing happen. Also when i try do this foreach:
foreach(IScore score in scoresFromLeaderboard)
{
Debug.Log("Score: " + score.formattedValue);
}
在 PlayGamePlatform.Instance.LoadScore {..}
之后,我没有得到并记录...
after PlayGamePlatform.Instance.LoadScore{..}
i don't get and Logs...
在官方文档中,似乎可以从排行榜保存信息,但是当我尝试这样做时,我没有在变量中得到任何字符串(来自Google Play插件git的代码):
In official documentation it's look like save information from leaderboard is possible, but when i try to do like this i don't get any string in variable(code from google play plugin git):
PlayGamesPlatform.Instance.LoadScores(
GPGSIds.leaderboard_leaders_in_smoketesting,
LeaderboardStart.PlayerCentered,
100,
LeaderboardCollection.Public,
LeaderboardTimeSpan.AllTime,
(data) =>
{
mStatus = "Leaderboard data valid: " + data.Valid;
mStatus += "\n approx:" +data.ApproximateCount + " have " + data.Scores.Length;
});
有人知道我在做什么错吗?
Somebody know what i am doing wrong?
推荐答案
试图在此处回答一个较旧的问题,但我自己遇到了完全相同的问题.到目前为止,这是我的解决方案,希望对您有所帮助.
Trying to answer an older question here, but ran into exact same problem myself. Here's my solution so far, hope it helps others.
我将其更改为:GPGSIds.leaderboard_leaders_in_smoketesting以字符串形式("abcd123")更改为我的实际排行榜ID.
I changed this: GPGSIds.leaderboard_leaders_in_smoketesting to my actual leaderboard ID as a string ("abcd123").
此外,尝试使用LeaderboardCollection.Social而不是.Public.看看是否返回数据.
Also, try to use LeaderboardCollection.Social instead of .Public. See if that returns data.
通过上述操作,我看到了Xcode日志中返回的数据.
By doing the above, I see data returned in the Xcode logs.
但是我必须承认,我也遇到了很多挑战.最令人烦恼的是,您无法在Unity本身中测试这些功能,而您每次都必须在设备上进行测试,这是一个巨大的痛苦.
But I must admit, I am running into quite a few challenges as well. Most annoying is that you can't test any of this stuff in Unity itself, you have to test on the device each time, which is a massive pain.
这篇关于Unity3d,GooglePlayServices和PlayGamesPlatform.Instance.LoadScores-不能将值写入变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!