Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix load more scores api. #2694

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions samples/SmokeTest/Source/Assets/SmokeTest/LeaderboardGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class LeaderboardGUI : MonoBehaviour
{
private MainGui mOwner;
private string mStatus;
private LeaderboardScoreData mScoreData;

// Constructed by the main gui
internal LeaderboardGUI(MainGui owner)
Expand Down Expand Up @@ -71,6 +72,14 @@ internal void OnGUI()
DoSocialLoadScores();
}

if (GUILayout.Button("Load More Scores", GUILayout.Height(height), GUILayout.ExpandWidth(true)))
{
DoLoadMoreScores();
}

GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(GUILayout.Height(height));

if (GUILayout.Button("Back", GUILayout.Height(height), GUILayout.ExpandWidth(true)))
{
mOwner.SetUI(MainGui.Ui.Main);
Expand Down Expand Up @@ -113,13 +122,14 @@ internal void DoSocialLoadScores()
PlayGamesPlatform.Instance.LoadScores(
GPGSIds.leaderboard_leaders_in_smoketesting,
LeaderboardStart.PlayerCentered,
100,
/* rowCount= */ 25,
LeaderboardCollection.Social,
LeaderboardTimeSpan.AllTime,
(data) =>
{
mStatus = "Leaderboard data valid: " + data.Valid;
mStatus += "\n approx:" + data.ApproximateCount + " have " + data.Scores.Length;
mScoreData = data;
});
}

Expand All @@ -128,17 +138,45 @@ internal void DoPublicLoadScores()
PlayGamesPlatform.Instance.LoadScores(
GPGSIds.leaderboard_leaders_in_smoketesting,
LeaderboardStart.PlayerCentered,
100,
/* rowCount= */ 25,
LeaderboardCollection.Public,
LeaderboardTimeSpan.AllTime,
(data) =>
{
mStatus = "LB data Status: " + data.Status;
mStatus += " valid: " + data.Valid;
mStatus += "\n approx:" + data.ApproximateCount + " have " + data.Scores.Length;
mScoreData = data;
});
}

internal void DoLoadMoreScores()
{
if (mScoreData == null)
{
mStatus = "mScoreData is null.";
return;
}

PlayGamesPlatform.Instance.LoadMoreScores(mScoreData.NextPageToken, 10,
(data) =>
{
if (data.Status == ResponseStatus.InternalError)
{
mStatus = "Internal error";
mScoreData = null;
}
else
{
mStatus = "LB data Status: " + data.Status;
mStatus += " valid: " + data.Valid;
mStatus += "\n approx:" + data.ApproximateCount + " have " + data.Scores.Length;
mScoreData = data;
}
}
);
}

internal void DoLoadLeaderboard()
{
ILeaderboard lb = PlayGamesPlatform.Instance.CreateLeaderboard();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -890,37 +890,35 @@ private LeaderboardScoreData CreateLeaderboardScoreData(
AndroidJavaObject leaderboardScoresJava)
{
LeaderboardScoreData leaderboardScoreData = new LeaderboardScoreData(leaderboardId, status);
using (var scoresBuffer = leaderboardScoresJava.Call<AndroidJavaObject>("getScores"))
var scoresBuffer = leaderboardScoresJava.Call<AndroidJavaObject>("getScores");
int count = scoresBuffer.Call<int>("getCount");
for (int i = 0; i < count; ++i)
{
int count = scoresBuffer.Call<int>("getCount");
for (int i = 0; i < count; ++i)
using (var leaderboardScore = scoresBuffer.Call<AndroidJavaObject>("get", i))
{
using (var leaderboardScore = scoresBuffer.Call<AndroidJavaObject>("get", i))
{
long timestamp = leaderboardScore.Call<long>("getTimestampMillis");
System.DateTime date = AndroidJavaConverter.ToDateTime(timestamp);
long timestamp = leaderboardScore.Call<long>("getTimestampMillis");
System.DateTime date = AndroidJavaConverter.ToDateTime(timestamp);

ulong rank = (ulong) leaderboardScore.Call<long>("getRank");
string scoreHolderId = "";
using (var scoreHolder = leaderboardScore.Call<AndroidJavaObject>("getScoreHolder"))
{
scoreHolderId = scoreHolder.Call<string>("getPlayerId");
}
ulong rank = (ulong) leaderboardScore.Call<long>("getRank");
string scoreHolderId = "";
using (var scoreHolder = leaderboardScore.Call<AndroidJavaObject>("getScoreHolder"))
{
scoreHolderId = scoreHolder.Call<string>("getPlayerId");
}

ulong score = (ulong) leaderboardScore.Call<long>("getRawScore");
string metadata = leaderboardScore.Call<string>("getScoreTag");
ulong score = (ulong) leaderboardScore.Call<long>("getRawScore");
string metadata = leaderboardScore.Call<string>("getScoreTag");

leaderboardScoreData.AddScore(new PlayGamesScore(date, leaderboardId,
rank, scoreHolderId, score, metadata));
}
leaderboardScoreData.AddScore(new PlayGamesScore(date, leaderboardId,
rank, scoreHolderId, score, metadata));
}

leaderboardScoreData.NextPageToken = new ScorePageToken(scoresBuffer, leaderboardId, collection,
timespan, ScorePageDirection.Forward);
leaderboardScoreData.NextPageToken = new ScorePageToken(scoresBuffer, leaderboardId, collection,
timespan, ScorePageDirection.Backward);
}

leaderboardScoreData.NextPageToken = new ScorePageToken(scoresBuffer, leaderboardId, collection,
timespan, ScorePageDirection.Forward);
leaderboardScoreData.PrevPageToken = new ScorePageToken(scoresBuffer, leaderboardId, collection,
timespan, ScorePageDirection.Backward);

using (var leaderboard = leaderboardScoresJava.Call<AndroidJavaObject>("getLeaderboard"))
using (var variants = leaderboard.Call<AndroidJavaObject>("getVariants"))
using (var variant = variants.Call<AndroidJavaObject>("get", 0))
Expand Down