ShrinkSDK

Public Unity SDK packages and workspace. yeah, almost AI slop. ;)

com.cneicy.shrink-datasaver-integration-eventbus (2.1.2)

Published 2026-08-28 03:45:41 +08:00 by cneicy

Installation

registry=https://git.crash.work/api/packages/ShrinkSDK/npm/
npm install com.cneicy.shrink-datasaver-integration-eventbus@2.1.2
"com.cneicy.shrink-datasaver-integration-eventbus": "2.1.2"

About this package

ShrinkDataSaver 与 ShrinkEventBus 的桥接层,自动将存档/设置事件映射到事件总线。

ShrinkDataSaver.Integration.EventBus

把 ShrinkDataSaver 的设置、保存、加载、迁移和删除生命周期发布为 ShrinkEventBus 2.0 事件。

ContextLoader 通过 ShrinkDataSaverEventBusComponent 管理桥生命周期;独立宿主调用 DataSaverEventBusBridge.Register(),退出时调用 Unregister()。

事件均实现 IShrinkEvent:

  • SettingsChangedEvent
  • SaveStartedEvent / SaveCompletedEvent / SaveFailedEvent
  • LoadStartedEvent / LoadCompletedEvent / LoadFailedEvent
  • MigrationCompletedEvent
  • SlotDeletedEvent

订阅只使用 2.0 特性:

[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,只应在设置值确实可转换时调用。

Dependencies

Dependencies

ID Version
com.cneicy.shrink-context-core 0.1.0
com.cneicy.shrink-datasaver 2.2.2
com.cneicy.shrink-eventbus 2.0.0
com.cysharp.unitask 2.5.10

Keywords

save eventbus integration bridge
Details
npm
2026-08-28 03:45:41 +08:00
4
cneicy
3.5 KiB
Assets (1)
Versions (5) View all
2.2.0 2026-09-05
2.1.3 2026-08-28
2.1.2 2026-08-28
2.1.1 2026-08-26
2.1.0 2026-08-26