feat: add cross-engine platform services

This commit is contained in:
2026-09-05 02:33:55 +08:00
parent 1bfb99d4c3
commit 0030f5b794
10 changed files with 171 additions and 42 deletions
+8 -8
View File
@@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Cysharp.Threading.Tasks;
using Newtonsoft.Json.Linq;
using UnityEngine;
namespace ShrinkDataSaver
{
@@ -112,7 +112,7 @@ namespace ShrinkDataSaver
if (_watchers.TryGetValue(key, out var list))
foreach (var cb in list)
try { cb(value); } catch (Exception e) { Debug.LogException(e); }
try { cb(value); } catch (Exception e) { ShrinkDataSaverPlatform.Exception(e); }
}
private static async UniTaskVoid ScheduleWrite()
@@ -123,12 +123,12 @@ namespace ShrinkDataSaver
try
{
var delay = (int)(ShrinkDataSaverSettings.Instance.settingsWriteDebounceSeconds * 1000);
await UniTask.Delay(delay, cancellationToken: token);
var delay = (int)(ShrinkDataSaverPlatform.SettingsWriteDebounceSeconds * 1000);
await Task.Delay(delay, token);
await SaveAsync(token);
}
catch (OperationCanceledException) { }
catch (Exception e) { Debug.LogException(e); }
catch (Exception e) { ShrinkDataSaverPlatform.Exception(e); }
}
private static async UniTask<SettingsData> TryLoadWithFallbackAsync(CancellationToken ct)
@@ -149,7 +149,7 @@ namespace ShrinkDataSaver
var loaded = DataSerializer.Deserialize<SettingsData>(bytes) ?? new SettingsData();
if (!string.Equals(candidatePath, primaryPath, StringComparison.Ordinal))
{
Debug.LogWarning($"[ShrinkDataSaver] Settings 主文件损坏或缺失,已从备份恢复:{candidatePath}");
ShrinkDataSaverPlatform.Warning($"[ShrinkDataSaver] Settings 主文件损坏或缺失,已从备份恢复:{candidatePath}");
await _storage.WriteAsync(primaryPath, bytes, ct);
}
@@ -158,13 +158,13 @@ namespace ShrinkDataSaver
catch (Exception ex)
{
lastError = ex;
Debug.LogWarning($"[ShrinkDataSaver] 读取 Settings 副本失败:{candidatePath} / {ex.Message}");
ShrinkDataSaverPlatform.Warning($"[ShrinkDataSaver] 读取 Settings 副本失败:{candidatePath} / {ex.Message}");
}
}
if (lastError != null)
{
Debug.LogWarning("[ShrinkDataSaver] 所有 Settings 副本均不可用,已回退为空设置。");
ShrinkDataSaverPlatform.Warning("[ShrinkDataSaver] 所有 Settings 副本均不可用,已回退为空设置。");
}
return new SettingsData();