feat: 增强存档管理,优化异步存档逻辑,添加错误处理机制
This commit is contained in:
@@ -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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user