Assets/Scripts/Menu/Leaderboard.cs (view raw)
1using System.Collections.Generic;
2using System.Linq;
3
4[System.Serializable]
5public class Leaderboard
6{
7 private int maxRecordsNumber;
8 private List<Record> _records;
9 public List<Record> Records
10 {
11 get
12 {
13 _records = _records.OrderByDescending(y => y.Score).ThenBy(y => y.Name).ToList();
14 return _records;
15 }
16 set
17 {
18 _records = value;
19 }
20 }
21
22 public void AddRecord(Record newRecord)
23 {
24 if(Records.Count == maxRecordsNumber)
25 { // full leaderboard
26 if(newRecord.Score > Records[maxRecordsNumber - 1].Score){
27 Records[maxRecordsNumber - 1] = newRecord;
28 }
29 } else {
30 Records.Add(newRecord);
31 }
32
33 }
34
35 public Leaderboard(int max){
36 maxRecordsNumber = max;
37 _records = new List<Record>();
38 }
39}