Files
Workspace/Assets/Modules/ShrinkDataSaver.Integration.EventBus/README.md
T
cneicy ad5a7b68a3 feat(sdk): migrate to EventBus 2.0
Replace the legacy EventBase runtime with generated multi-bus bindings and explicit scheduling. Migrate app, data, network, demo, and mod consumers; add generated network-event registration and owner-scoped mod content overrides.
2026-08-26 01:15:48 +08:00

40 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ShrinkDataSaver.Integration.EventBus
把 ShrinkDataSaver 的设置、保存、加载、迁移和删除生命周期发布为 ShrinkEventBus 2.0 事件。
ContextLoader 通过 `ShrinkDataSaverEventBusComponent` 管理桥生命周期;独立宿主调用 `DataSaverEventBusBridge.Register()`,退出时调用 `Unregister()`
事件均实现 `IShrinkEvent`
- `SettingsChangedEvent`
- `SaveStartedEvent` / `SaveCompletedEvent` / `SaveFailedEvent`
- `LoadStartedEvent` / `LoadCompletedEvent` / `LoadFailedEvent`
- `MigrationCompletedEvent`
- `SlotDeletedEvent`
订阅只使用 2.0 特性:
```csharp
[ShrinkEventSubscriber(DefaultBus = "game")]
public sealed class SaveUiHandlers
{
[ShrinkSubscribe]
private void OnSaved(SaveCompletedEvent value)
{
Debug.Log($"slot {value.SlotIndex} saved");
}
[ShrinkSubscribe(Priority = ShrinkEventPriority.Low)]
private void OnLoadFailed(LoadFailedEvent value)
{
Debug.LogError(value.ErrorMessage);
}
}
using var binding = EventBus.Attach(new SaveUiHandlers());
```
桥接方向是 DataSaver -> EventBus,发布使用 `EventBus.Post(...)`。没有手工 Delegate 注册或旧 Trigger API。
`SettingsChangedEvent.Get<T>()` 内部使用 `Convert.ChangeType`,只应在设置值确实可转换时调用。