feat: add opt-in MonoBehaviour lifecycle weaving
Publish UPM package / publish (push) Successful in 2s
Publish UPM package / publish (push) Successful in 2s
This commit is contained in:
@@ -80,7 +80,18 @@ Bus 解析顺序:方法 `Bus`、类型 `DefaultBus`、`Attach` 传入默认 Bu
|
||||
using var binding = EventBus.Attach(new PlayerHandlers());
|
||||
```
|
||||
|
||||
MonoBehaviour 不需要继承 SDK 基类。可自行在 `OnEnable/OnDisable` 中 Attach/Dispose,也可以在 GameObject 上添加 `ShrinkMonoEventScope`,由它统一绑定同对象或子层级中的生成 subscriber。
|
||||
MonoBehaviour 不需要继承 SDK 基类。需要从 `Awake` 持续订阅到 `OnDestroy` 时,可以显式选择编译期生命周期织入:
|
||||
|
||||
```csharp
|
||||
[ShrinkEventSubscriber(Lifetime = ShrinkSubscriberLifetime.AwakeToDestroy)]
|
||||
public sealed class PlayerHandlers : MonoBehaviour
|
||||
{
|
||||
[ShrinkSubscribe]
|
||||
private void OnJoined(PlayerJoinedEvent value) { }
|
||||
}
|
||||
```
|
||||
|
||||
默认 `Lifetime` 为 `Manual`,普通对象与由 Context、Scene 或 Mod 宿主管理的实例继续自行持有 `EventBus.Attach(...)` 返回的绑定。需要随启用状态反复订阅的 MonoBehaviour 可以自行在 `OnEnable/OnDisable` 中 Attach/Dispose,也可以在 GameObject 上添加 `ShrinkMonoEventScope`,由它统一绑定同对象或子层级中的生成 subscriber。
|
||||
|
||||
静态类型同样只使用特性:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user