You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.9 KiB
C#
60 lines
1.9 KiB
C#
1 month ago
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using PlayFab;
|
||
|
using PlayFab.ClientModels;
|
||
|
using UnityEngine;
|
||
|
|
||
|
public class LeaderboardUIScreen : MonoBehaviour
|
||
|
{
|
||
|
[SerializeField] private GameObject lbItemPrefab;
|
||
|
[SerializeField] private GameObject lbItemSelfPrefab;
|
||
|
[SerializeField] private Transform content;
|
||
|
[SerializeField] private List<LBPedestalItem> _lbPedestalItems;
|
||
|
|
||
|
public void Init()
|
||
|
{
|
||
|
PlayFabManager.Instance.playFabLeaderboards.GetLeaderboard(OnLeaderboardFetchSuccess, OnLeaderboardFetchFailure);
|
||
|
}
|
||
|
|
||
|
private void OnLeaderboardFetchSuccess(List<PlayerLeaderboardEntry> leaderboard)
|
||
|
{
|
||
|
PopulateLeaderboard(leaderboard);
|
||
|
}
|
||
|
|
||
|
private void PopulateLeaderboard(List<PlayerLeaderboardEntry> leaderboard)
|
||
|
{
|
||
|
foreach (PlayerLeaderboardEntry lbEntry in leaderboard)
|
||
|
{
|
||
|
PopulateLbItem(lbEntry);
|
||
|
if (lbEntry.Position <= 3)
|
||
|
{
|
||
|
PopulatePedestalItem(lbEntry);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
private void PopulateLbItem(PlayerLeaderboardEntry lbEntry)
|
||
|
{
|
||
|
bool isSelf = lbEntry.Profile.PlayerId == PlayFabManager.Instance.myProfile.PlayerId;
|
||
|
LBEntryItem lbItem = Instantiate(isSelf ? lbItemSelfPrefab : lbItemPrefab, content).GetComponent<LBEntryItem>();
|
||
|
lbItem.nameText.text = lbEntry.DisplayName;
|
||
|
lbItem.rankText.text = (lbEntry.Position + 1).ToString();
|
||
|
lbItem.scoreText.text = lbEntry.StatValue.ToString();
|
||
|
}
|
||
|
|
||
|
private void PopulatePedestalItem(PlayerLeaderboardEntry lbEntry)
|
||
|
{
|
||
|
LBPedestalItem pedestalItem = _lbPedestalItems[lbEntry.Position];
|
||
|
pedestalItem.nameText.text = lbEntry.DisplayName??lbEntry.PlayFabId;
|
||
|
pedestalItem.scoreText.text = lbEntry.StatValue.ToString();
|
||
|
}
|
||
|
|
||
|
private void OnLeaderboardFetchFailure(PlayFabError obj)
|
||
|
{
|
||
|
Debug.Log("Couldn't Load Leaderboards");
|
||
|
throw new System.NotImplementedException();
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|