/// <summary> /// Fill the leaderboard panel with nonpaged scores then show it. /// </summary> /// <param name="scoresList">List of the scores to display.</param> /// <param name="noScoreErrorMessage">Error message to display in case of no score to display.</param> public void FillNonpagedLeaderboardPanel(NonpagedList <Score> scoresList, string noScoreErrorMessage = "(no score to display)") { // Clear the leaderboard panel ClearLeaderboardPanel(false); // If there are scores to display, fill the leaderboard panel with score prefabs if ((scoresList != null) && (scoresList.Count > 0)) { foreach (Score score in scoresList) { // Create a leaderboard score GameObject and hook it at the leaderboard items layout GameObject prefabInstance = Instantiate <GameObject>(leaderboardScorePrefab); prefabInstance.transform.SetParent(leaderboardItemsLayout.transform, false); // Fill the newly created GameObject with score data LeaderboardScoreHandler leaderboardScoreHandler = prefabInstance.GetComponent <LeaderboardScoreHandler>(); leaderboardScoreHandler.FillData(score); // Add the newly created GameObject to the list leaderboardItems.Add(prefabInstance); } } // Else, show the "no score" text else { noScoreText.text = noScoreErrorMessage; noScoreText.gameObject.SetActive(true); } }
/// <summary> /// Fill the leaderboard panel with paged scores then show it. /// </summary> /// <param name="scoresList">List of the scores to display.</param> /// <param name="noScoreErrorMessage">Error message to display in case of no score to display.</param> public void FillPagedLeaderboardPanel(PagedList <Score> scoresList, string noScoreErrorMessage = "(no score to display)") { // Clear the leaderboard panel ClearLeaderboardPanel(false); // If there are scores to display, fill the leaderboard panel with score prefabs if ((scoresList != null) && (scoresList.Count > 0)) { foreach (Score score in scoresList) { // Create a leaderboard score GameObject and hook it at the leaderboard items layout GameObject prefabInstance = Instantiate <GameObject>(leaderboardScorePrefab); prefabInstance.transform.SetParent(leaderboardItemsLayout.transform, false); // Fill the newly created GameObject with score data LeaderboardScoreHandler leaderboardScoreHandler = prefabInstance.GetComponent <LeaderboardScoreHandler>(); leaderboardScoreHandler.FillData(score); // Add the newly created GameObject to the list leaderboardItems.Add(prefabInstance); } // Keep the last PagedList<Score> to allow fetching of previous and next leaderboard pages and show the previous page and next page buttons currentScoresList = scoresList; previousPageButton.interactable = currentScoresList.HasPrevious; nextPageButton.interactable = currentScoresList.HasNext; pageButtons.SetActive(true); } // Else, show the "no score" text and reset the current scores list else { noScoreText.text = noScoreErrorMessage; noScoreText.gameObject.SetActive(true); currentScoresList = null; } }