Tic Tac Toe Example LeaderboardsLobby - TogetherGames/Public-Unity-CSharp GitHub Wiki
The LeaderboardsLobby screen displays a list of Leaderboards the User is a member of. A Leaderboard is generated whenever a GameInstance is finished.
The Start() method calls AchievementManager.GetAll() method to retrieve all game configured Achievements.
Together.Instance.LeaderboardManager.GetAll(m_User.UserID, onGotAllLeaderboards); // callbackFunc
The DisplayButtons() method displays a button for every Leaderboard retrieved.
void DisplayButtons()
{
if( GUI.Button(new Rect(10, 50, 100, 50), "Back"))
Application.LoadLevel("MainMenu");
//if( GUI.Button(new Rect((Screen.width - 200) * 0.5f, (Screen.height - 50 ) * 0.5f, 200, 50), "Leaderboard1"))
// Application.LoadLevel("Leaderboard");
PlaysTogether.Leaderboard leaderboard;
int winningScore = 0;
if (m_bDisplay)
{
for (int i = 0; i < m_leaderboards.Length; i++)
{
leaderboard = m_leaderboards[i];
winningScore = GetLeaderboardWinningScore(leaderboard);
string display = "ID=" + leaderboard.LeaderboardID + ", WinUser=" + leaderboard.WinningUserID + ", WinScore=" + winningScore;
if( GUI.Button(new Rect((Screen.width - 400) * 0.5f, 200 + (60 * i), buttonWidth, 50), display))
{
//Save the data for the leaderboard scene
Helper.UserData = m_leaderboards[i];
Application.LoadLevel("Leaderboard");
}
}
}
}
When a Leaderboard button is pressed, the Leaderboard pressed is assigned to the Helper.UserData member before the Leaderboard scene is loaded. The Helper.UserData member is used to pass initialization data from one screen to another.
if( GUI.Button(new Rect((Screen.width - 400) * 0.5f, 200 + (60 * i), buttonWidth, 50), display))
{
//Save the data for the leaderboard scene
Helper.UserData = m_leaderboards[i];
Application.LoadLevel("Leaderboard");
}