UPF/Assets/Game/Scripts/GlobalLeaderboard.cs
2022-09-03 02:21:20 +05:30

29 lines
978 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GlobalLeaderboard : MonoBehaviour
{
public Transform leaderboardItemsParent;
public LeaderboardItem template;
public async void Show(){
List<LeaderboardUserData> leaderboard = await DBmanager.GetLeaderboard();
template.gameObject.SetActive(true);
//Clear currentItems
for(int i=0; i < leaderboardItemsParent.childCount; i++){
if(leaderboardItemsParent.GetChild(i) == template.transform){
continue;
}
Destroy(leaderboardItemsParent.GetChild(i).gameObject);
}
for(int i =0; i < leaderboard.Count; i++){
LeaderboardItem newItem = Instantiate(template.gameObject, leaderboardItemsParent).GetComponent<LeaderboardItem>();
newItem.Set(leaderboard[i]);
}
template.gameObject.SetActive(false);
gameObject.SetActive(true);
}
}