Unity3d, GooglePlayServices and PlayGamesPlatform.Instance.LoadScores - can't write values to variable

孤街醉人 提交于 2020-02-08 03:08:27

问题


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);
                    }

                }
    );

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);
                    }

after PlayGamePlatform.Instance.LoadScore{..} i don't get and Logs...

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?


回答1:


Trying to answer an older question here, but ran into exact same problem myself. Here's my solution so far, hope it helps others.

I changed this: GPGSIds.leaderboard_leaders_in_smoketesting to my actual leaderboard ID as a string ("abcd123").

Also, try to use LeaderboardCollection.Social instead of .Public. See if that returns data.

By doing the above, I see data returned in the Xcode logs.

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.



来源:https://stackoverflow.com/questions/37258240/unity3d-googleplayservices-and-playgamesplatform-instance-loadscores-cant-wr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!