feat: 增强存档管理,优化异步存档逻辑,添加错误处理机制

This commit is contained in:
2026-05-20 16:52:22 +08:00
parent 04aec4cc8e
commit e50cf57321
6 changed files with 30 additions and 15 deletions

View File

@@ -1,3 +1,5 @@
using System;
using System.Threading.Tasks;
using UnityEngine;
using BaseGames.Core;
using BaseGames.Core.Events;
@@ -68,7 +70,7 @@ namespace BaseGames.World
// 触发存档OnSave() 由 SaveAsync 回调所有 ISaveable包含本组件
var svc = ServiceLocator.GetOrDefault<ISaveService>();
if (svc != null)
_ = svc.SaveAsync(svc.ActiveSlot);
RunFireAndForget(svc.SaveAsync(svc.ActiveSlot));
else
Debug.LogWarning("[SavePoint] ISaveService 未注册,跳过存档。", this);
}
@@ -101,6 +103,14 @@ namespace BaseGames.World
_isActivated = !string.IsNullOrEmpty(_savePointId)
&& data.World.ActivatedSavePoints.Contains(_savePointId);
}
private static async void RunFireAndForget(Task task)
{
try { await task; }
catch (Exception e)
{
Debug.LogError($"[SavePoint] 存档失败: {e.Message}\n{e.StackTrace}");
}
}
}
}