Files
ShrinkDataSaver.Integration…/ShrinkDataSaverEventBusComponent.cs
T
cneicy 2926ce5952
Publish UPM package / publish (push) Failing after 1s
chore: initialize standalone UPM package
2026-08-26 02:50:13 +08:00

36 lines
1.2 KiB
C#

#nullable enable
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using ShrinkContext;
namespace ShrinkDataSaver.Integration
{
/// <summary>注入 DataSaver 服务键并把其原生事件显式接到 EventBus。</summary>
public sealed class ShrinkDataSaverEventBusComponent : IShrinkComponent
{
public const string DataSaverServiceKey = "shrink.service.datasaver";
public const string ProvideKey = "shrink.integration.datasaver-eventbus";
private static readonly string[] InjectKeys = { DataSaverServiceKey };
private static readonly string[] ProvideKeys = { ProvideKey };
public string Name => "shrink.integration.datasaver-eventbus";
public IReadOnlyList<string> Inject => InjectKeys;
public IReadOnlyList<string> Provide => ProvideKeys;
public UniTask ApplyAsync(ShrinkCtx ctx, object? config)
{
_ = ctx.Get<object>(DataSaverServiceKey);
DataSaverEventBusBridge.Register();
ctx.EffectInverse(() =>
{
DataSaverEventBusBridge.Unregister();
return UniTask.CompletedTask;
});
ctx.Set(ProvideKey, Name);
return UniTask.CompletedTask;
}
}
}