Files
ShrinkContext.EventBusAdapter/Runtime/ShrinkEventBusEffects.cs
T
cneicy b00f0b3684
Publish UPM package / publish (push) Failing after 1s
chore: initialize standalone UPM package
2026-08-26 02:50:01 +08:00

34 lines
1012 B
C#

#nullable enable
using System;
using Cysharp.Threading.Tasks;
using ShrinkContext;
using ShrinkEventBus;
namespace ShrinkContext.EventBusAdapter
{
/// <summary>
/// 把生成的 ShrinkEventBus 绑定包装为可逆效应。
/// </summary>
public static class ShrinkEventBusEffects
{
/// <summary>
/// 激活生成的 [ShrinkSubscribe] 绑定,并在 Context 回滚时统一释放。
/// </summary>
public static ShrinkEffectHandle EffectAttach(this ShrinkCtx ctx, object target,
ShrinkBusKey? defaultBus = null)
{
if (ctx == null)
throw new ArgumentNullException(nameof(ctx));
if (target == null)
throw new ArgumentNullException(nameof(target));
var binding = EventBus.Attach(target, defaultBus);
return ctx.EffectInverse(() =>
{
binding.Dispose();
return UniTask.CompletedTask;
});
}
}
}