feat: 更新存档管理,添加异步存档槽管理功能,优化存档验证逻辑
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using BaseGames.Core.Events;
|
||||
@@ -105,12 +106,20 @@ namespace BaseGames.Core
|
||||
#if UNITY_EDITOR || DEVELOPMENT_BUILD
|
||||
Debug.Log($"[AutoSave] 触发:{reason}");
|
||||
#endif
|
||||
// 与手动存档使用相同槽位,fire-and-forget
|
||||
_ = svc.SaveAsync(svc.ActiveSlot);
|
||||
RunFireAndForget(svc.SaveAsync(svc.ActiveSlot), reason);
|
||||
}
|
||||
|
||||
yield return new WaitForSecondsRealtime(_cooldownSeconds);
|
||||
_onCooldown = false;
|
||||
}
|
||||
|
||||
private static async void RunFireAndForget(System.Threading.Tasks.Task task, string context)
|
||||
{
|
||||
try { await task; }
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError($"[AutoSave] {context} 存档失败: {e.Message}\n{e.StackTrace}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,5 +232,10 @@ namespace BaseGames.Core
|
||||
public System.Collections.Generic.IEnumerable<string> GetCompletedChains() => _save.GetCompletedChains();
|
||||
public void SetChainCompleted(string chainId) => _save.SetChainCompleted(chainId);
|
||||
public void MarkBossDefeated(string bossId) => _save.MarkBossDefeated(bossId);
|
||||
|
||||
// ── 存档槽管理(主菜单 UI 用)─────────────────────────────────────────
|
||||
public System.Threading.Tasks.Task<BaseGames.Core.Save.SlotSummary> GetSlotSummaryAsync(int slotIndex)
|
||||
=> _save.GetSlotSummaryAsync(slotIndex);
|
||||
public void CreateSlot(int slotIndex) => _save.CreateSlot(slotIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using BaseGames.Core.Save;
|
||||
|
||||
namespace BaseGames.Core
|
||||
{
|
||||
@@ -76,5 +77,13 @@ namespace BaseGames.Core
|
||||
|
||||
/// <summary>标记某个 Boss 已被击败,立即写入当前 SaveData(无需等待下次存档)。</summary>
|
||||
void MarkBossDefeated(string bossId);
|
||||
|
||||
// ── 存档槽管理(主菜单 UI 用)────────────────────────────────────────
|
||||
|
||||
/// <summary>读取指定存档槽摘要数据用于 UI 展示;槽不存在时返回 null。</summary>
|
||||
Task<SlotSummary> GetSlotSummaryAsync(int slotIndex);
|
||||
|
||||
/// <summary>新建存档槽(不写盘,仅初始化内存 SaveData 并设定活跃槽索引)。</summary>
|
||||
void CreateSlot(int slotIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ namespace BaseGames.Core.Save
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ValidateChecksum(loaded, json))
|
||||
if (!ValidateChecksum(loaded))
|
||||
{
|
||||
if (loaded.Meta.IsSteelSoul)
|
||||
{
|
||||
@@ -278,7 +278,7 @@ namespace BaseGames.Core.Save
|
||||
return gameSecret;
|
||||
}
|
||||
|
||||
private bool ValidateChecksum(SaveData data, string rawJson)
|
||||
private bool ValidateChecksum(SaveData data)
|
||||
{
|
||||
if (string.IsNullOrEmpty(data?.Meta?.Checksum)) return true;
|
||||
var saved = data.Meta.Checksum;
|
||||
|
||||
Reference in New Issue
Block a user