feat: update Godot integration and coordinated package dependencies
This commit is contained in:
6 files changed
+96
-28
No files matched your search
@@ -21,6 +21,16 @@ namespace ShrinkDataSaver.Integration.App
|
||||
public const string ModuleKey = "app.module.shrink.datasaver";
|
||||
|
||||
private static readonly string[] ProvideKeys = { ModuleKey, ServiceKey };
|
||||
private readonly ShrinkDataSaverRuntimeConfig? _runtimeConfig;
|
||||
|
||||
public ShrinkDataSaverAppComponent()
|
||||
{
|
||||
}
|
||||
|
||||
public ShrinkDataSaverAppComponent(ShrinkDataSaverRuntimeConfig? runtimeConfig)
|
||||
{
|
||||
_runtimeConfig = runtimeConfig;
|
||||
}
|
||||
|
||||
public string Name => "shrink.datasaver";
|
||||
|
||||
@@ -28,22 +38,27 @@ namespace ShrinkDataSaver.Integration.App
|
||||
|
||||
public IReadOnlyList<string> Provide => ProvideKeys;
|
||||
|
||||
public async UniTask ApplyAsync(ShrinkCtx ctx, object? config)
|
||||
public UniTask ApplyAsync(ShrinkCtx ctx, object? config)
|
||||
{
|
||||
// 编辑器/EditMode 环境下 DontDestroyOnLoad 会抛异常,驱动只在播放模式常驻
|
||||
ShrinkDataSaverRuntime.Initialize(new ShrinkDataSaverRuntimeConfig
|
||||
ShrinkAppServices? appServices = null;
|
||||
var runtimeConfig = _runtimeConfig ?? CreateDefaultRuntimeConfig();
|
||||
if (config is ShrinkDataSaverAppModuleConfig moduleConfig)
|
||||
{
|
||||
#if UNITY_5_3_OR_NEWER
|
||||
DontDestroyOnLoadDriver = UnityEngine.Application.isPlaying
|
||||
#else
|
||||
DontDestroyOnLoadDriver = false
|
||||
#endif
|
||||
});
|
||||
appServices = moduleConfig.Services;
|
||||
if (moduleConfig.RuntimeConfig != null)
|
||||
runtimeConfig = moduleConfig.RuntimeConfig;
|
||||
}
|
||||
else if (config is ShrinkAppServices services)
|
||||
{
|
||||
appServices = services;
|
||||
}
|
||||
|
||||
ShrinkDataSaverRuntime.Initialize(runtimeConfig);
|
||||
var facade = new ShrinkDataSaverService();
|
||||
ctx.Set(ServiceKey, facade, new ShrinkDataSaverAccessPolicy(facade));
|
||||
ctx.Set(ModuleKey, Name);
|
||||
|
||||
if (config is ShrinkAppServices appServices)
|
||||
if (appServices != null)
|
||||
{
|
||||
appServices.Register(facade);
|
||||
ctx.EffectInverse(() =>
|
||||
@@ -53,17 +68,24 @@ namespace ShrinkDataSaver.Integration.App
|
||||
});
|
||||
}
|
||||
|
||||
await ctx.EffectAsync(async () =>
|
||||
ctx.EffectInverse(async () =>
|
||||
{
|
||||
await UniTask.CompletedTask;
|
||||
return () =>
|
||||
{
|
||||
// 终止动作(触发式):停用时把防抖中的设置写盘。
|
||||
// 磁盘 IO 在线程池完成,不阻塞停用链;未初始化环境安全跳过(SaveAsync 守卫)。
|
||||
ShrinkSettings.SaveAsync().Forget();
|
||||
return UniTask.CompletedTask;
|
||||
};
|
||||
await ShrinkSettings.SaveAsync();
|
||||
});
|
||||
return UniTask.CompletedTask;
|
||||
}
|
||||
|
||||
private static ShrinkDataSaverRuntimeConfig CreateDefaultRuntimeConfig()
|
||||
{
|
||||
// 编辑器/EditMode 环境下 DontDestroyOnLoad 会抛异常,驱动只在播放模式常驻
|
||||
return new ShrinkDataSaverRuntimeConfig
|
||||
{
|
||||
#if UNITY_5_3_OR_NEWER
|
||||
DontDestroyOnLoadDriver = UnityEngine.Application.isPlaying
|
||||
#else
|
||||
DontDestroyOnLoadDriver = false
|
||||
#endif
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#nullable enable
|
||||
|
||||
using ShrinkApp;
|
||||
|
||||
namespace ShrinkDataSaver.Integration.App
|
||||
{
|
||||
public sealed class ShrinkDataSaverAppModuleConfig
|
||||
{
|
||||
public ShrinkDataSaverAppModuleConfig()
|
||||
{
|
||||
}
|
||||
|
||||
public ShrinkDataSaverAppModuleConfig(ShrinkAppServices? services,
|
||||
ShrinkDataSaverRuntimeConfig? runtimeConfig = null)
|
||||
{
|
||||
Services = services;
|
||||
RuntimeConfig = runtimeConfig;
|
||||
}
|
||||
|
||||
public ShrinkAppServices? Services { get; set; }
|
||||
public ShrinkDataSaverRuntimeConfig? RuntimeConfig { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bd27f288ce72493889806887d825b37d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in new issue
Block a user