added results

This commit is contained in:
MrTorex committed 2026-01-27 19:32:01 +03:00
1 parent 586c476851
commit bae0e2218e
11 files changed
+617 -5

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using UnityEngine;
namespace Code.Records
{
public class RecordsService
{
private const string Key = "RaceRecords";
public static List<Record> Load()
{
var json = PlayerPrefs.GetString(Key, "[]");
try
{
return JsonConvert.DeserializeObject<List<Record>>(json) ?? new List<Record>();
}
catch
{
return new List<Record>();
}
}
public static void Save(List<Record> records)
{
var json = JsonConvert.SerializeObject(records);
PlayerPrefs.SetString(Key, json);
PlayerPrefs.Save();
}
public static void AddRecord(string name, long totalMs)
{
var records = Load();
records.Add(new Record(name, totalMs));
records = records.OrderBy(r => r.totalMilliseconds).ToList();
records = records.Take(5).ToList();
Save(records);
}
}
}