Tic Tac Toe Example Leaderboard - TogetherGames/Public-Unity-CSharp GitHub Wiki

The Leaderboard screen displays all the info for a particular Together Leaderboard. The DisplayText() method displays labels containing the Leaderboard's information. The DisplayButtons() method displays the Award button and the Purchase button.

The Start() method calls Leaderboard.GetDetails() method to retrieve all the information pertaining to the Leaderboard to display.

m_Leaderboard.GetDetails(false,                     // friendsOnly
                         onGotLeaderboardDetails);  // callbackFunc

The DisplayLeaderboardInfo() method displays many labels showing all the Leaderboards information. The Users belonging to the Leaderboard are displayed as well.

void DisplayLeaderboardInfo()
{
    int labelY = 100;
    int labelYStep = 30;
    int winningScore = GetWinningScore();

    GUI.Label(new Rect((Screen.width - 300) * 0.5f, 25, 300, 100), "Leaderboard", m_TitleStyle);

    //Create and set the labels
    GUI.Label(new Rect((Screen.width - 300) * 0.5f, labelY, 300, 100), "LeaderboardID = " + m_Leaderboard.LeaderboardID, m_TextStyle);
    labelY += labelYStep;
    GUI.Label(new Rect((Screen.width - 300) * 0.5f, labelY, 300, 100), "CreatorUserID = " + m_Leaderboard.CreatorUserID, m_TextStyle);
    labelY += labelYStep;
    GUI.Label(new Rect((Screen.width - 300) * 0.5f, labelY, 300, 100),"RoomID = " + m_Leaderboard.RoomID, m_TextStyle);
    labelY += labelYStep;
    GUI.Label(new Rect((Screen.width - 300) * 0.5f, labelY, 300, 100), "SecondsSinceStart = " + m_Leaderboard.SecondsSinceStart, m_TextStyle);
    labelY += labelYStep;
    GUI.Label(new Rect((Screen.width - 300) * 0.5f, labelY, 300, 100), "SecondsSinceFinish = " + m_Leaderboard.SecondsSinceFinish, m_TextStyle);
    labelY += labelYStep;
    GUI.Label(new Rect((Screen.width - 300) * 0.5f, labelY, 300, 100), "MaxUsers = "+ m_Leaderboard.MaxUsers, m_TextStyle);
    labelY += labelYStep;
    GUI.Label(new Rect((Screen.width - 300) * 0.5f, labelY, 300, 100), "TurnIndex = " + m_Leaderboard.TurnIndex, m_TextStyle);
    labelY += labelYStep;
    GUI.Label(new Rect((Screen.width - 300) * 0.5f, labelY, 300, 100), "WinningUserID = " + m_Leaderboard.WinningUserID, m_TextStyle);
    labelY += labelYStep;
    GUI.Label(new Rect((Screen.width - 300) * 0.5f, labelY, 300, 100), "WinningScore = " + winningScore, m_TextStyle);
    labelY += labelYStep;
}

The DisplayLeaderboardUsers() method displays all the Users belonging to the Leaderboard.

void DisplayLeaderboardUsers()
{
	int labelY = 400;
	int labelYStep = 30;
	LeaderboardUser leaderboardUser;

	for (int i=0; i<m_Leaderboard.GetLeaderboardUserCount(); i++)
	{
		leaderboardUser = m_Leaderboard.GetLeaderboardUser(i);

		GUI.Label(new Rect((Screen.width - 300) * 0.5f, labelY, 300, 50),
			leaderboardUser.Username + ", Score=" + leaderboardUser.Properties.GetEx("Score", "0"), m_TextStyle);	

		labelY += 30;
	}
}