rabidus-test/Assets/LeaderboardController.cs

32 lines
753 B
C#
Raw Normal View History

2023-07-24 16:38:13 +03:00
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class LeaderboardController : MonoBehaviour
{
[SerializeField]
private RectTransform _content;
[SerializeField]
private LeaderboardEntry _leaderboardEntryPrefab;
[SerializeField]
private PlayerInfo _playerInfo;
private void Start()
{
UpdateLeaderboard();
}
private void UpdateLeaderboard()
{
var sortedList = _playerInfo.Players.OrderByDescending(x => x.Score).ToList();
for (int i = 0; i < sortedList.Count; i++)
{
var newEntry = Instantiate(_leaderboardEntryPrefab, _content);
newEntry.Init(sortedList[i], i);
}
}
}