rabidus-test/Assets/Scripts/LeaderboardWithDateControll...

35 lines
909 B
C#
Raw Normal View History

2023-10-05 17:56:59 +03:00
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public class LeaderboardWithDateController : LeaderboardController
{
public int DaysShow = 30;
protected override void Start()
{
base.Start();
}
protected override void UpdateLeaderboard()
{
_entries.ForEach(x => Destroy(x.gameObject));
_entries.Clear();
_entries = new List<LeaderboardEntry>();
var sortedList = PlayerSetup.Instance.AllPlayers
.Where(y => DateTime.Parse(y.DateTime)
.AddDays(DaysShow) >= DateTime.Now)
.OrderByDescending(x => x.Score)
.ToList();
for (int i = 0; i < sortedList.Count; i++)
{
var newEntry = Instantiate(_leaderboardEntryPrefab, _content);
_entries.Add(newEntry);
newEntry.Init(sortedList[i], i);
}
}
}