feat: add cross-engine platform services
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user