Files
ShrinkNetwork.Integration.E…/ShrinkNetworkEventBusComponent.cs
T
cneicy 05bfe9c430
Publish UPM package / publish (push) Failing after 1s
chore: initialize standalone UPM package
2026-08-26 02:50:38 +08:00

36 lines
1.3 KiB
C#

#nullable enable
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using ShrinkContext;
namespace ShrinkNetwork.Integration
{
/// <summary>通过网络服务键管理 Network ↔ EventBus 桥的可逆生命周期。</summary>
public sealed class ShrinkNetworkEventBusComponent : IShrinkComponent
{
public const string NetworkServiceKey = "shrink.service.network";
public const string ProvideKey = "shrink.integration.network-eventbus";
private static readonly string[] InjectKeys = { NetworkServiceKey };
private static readonly string[] ProvideKeys = { ProvideKey };
public string Name => "shrink.integration.network-eventbus";
public IReadOnlyList<string> Inject => InjectKeys;
public IReadOnlyList<string> Provide => ProvideKeys;
public UniTask ApplyAsync(ShrinkCtx ctx, object? config)
{
var service = ctx.Get<ShrinkNetworkService>(NetworkServiceKey);
service.UseEventBusBridge(config as ShrinkNetworkEventBusBridgeOptions);
ctx.EffectInverse(() =>
{
ShrinkNetworkEventBusBridge.UnregisterService(service);
return UniTask.CompletedTask;
});
ctx.Set(ProvideKey, Name);
return UniTask.CompletedTask;
}
}
}