加入用户最近100场战绩记录并实现展示
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public static class RecentPlayHistoryStore
|
||||
{
|
||||
private const string Category = "recent_play_history";
|
||||
private const string Key = "runs_v1";
|
||||
private const int MaxRecordCount = 100;
|
||||
|
||||
public static IReadOnlyList<RecentPlayRecord> GetRecords()
|
||||
{
|
||||
return LoadPayload().records;
|
||||
}
|
||||
|
||||
public static void Push(RecentPlayRecord record)
|
||||
{
|
||||
if (record == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var payload = LoadPayload();
|
||||
if (payload.records == null)
|
||||
{
|
||||
payload.records = new List<RecentPlayRecord>();
|
||||
}
|
||||
|
||||
payload.records.Insert(0, record);
|
||||
if (payload.records.Count > MaxRecordCount)
|
||||
{
|
||||
payload.records.RemoveRange(MaxRecordCount, payload.records.Count - MaxRecordCount);
|
||||
}
|
||||
|
||||
SecureSaveVault.SaveJson(Category, Key, payload);
|
||||
}
|
||||
|
||||
public static void Clear()
|
||||
{
|
||||
SecureSaveVault.Delete(Category, Key);
|
||||
}
|
||||
|
||||
private static RecentPlayHistoryPayload LoadPayload()
|
||||
{
|
||||
RecentPlayHistoryPayload payload;
|
||||
if (!SecureSaveVault.TryLoadJson(Category, Key, out payload) || payload == null)
|
||||
{
|
||||
payload = new RecentPlayHistoryPayload();
|
||||
}
|
||||
|
||||
if (payload.records == null)
|
||||
{
|
||||
payload.records = new List<RecentPlayRecord>();
|
||||
}
|
||||
|
||||
return payload;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user