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.
This commit is contained in:
+15
-16
@@ -1,21 +1,24 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using ShrinkEventBus;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ShrinkModFramework
|
||||
{
|
||||
internal static class ShrinkModOptionalRuntimeIntegration
|
||||
{
|
||||
public static void RegisterModInstance(IShrinkMod modInstance, ShrinkModInfo modInfo, bool verboseLogging)
|
||||
public static IDisposable RegisterModInstance(IShrinkMod modInstance, ShrinkModInfo modInfo,
|
||||
bool verboseLogging)
|
||||
{
|
||||
if (modInstance == null || modInfo == null)
|
||||
return;
|
||||
return null;
|
||||
|
||||
var modType = modInstance.GetType();
|
||||
TryRegisterEventBusInstance(modType, modInstance, modInfo.ModId, verboseLogging);
|
||||
var eventBinding = TryAttachEventBusInstance(modType, modInstance, modInfo.ModId, verboseLogging);
|
||||
TryRegisterCommandInstance(modType, modInstance, modInfo.ModId, verboseLogging);
|
||||
TryRegisterNetworkInstance(modType, modInstance, modInfo.ModId, verboseLogging);
|
||||
return eventBinding;
|
||||
}
|
||||
|
||||
public static void RefreshGlobalBindings(bool verboseLogging)
|
||||
@@ -23,29 +26,25 @@ namespace ShrinkModFramework
|
||||
TryRefreshNetworkEventBusBridge(verboseLogging);
|
||||
}
|
||||
|
||||
private static void TryRegisterEventBusInstance(Type modType, object modInstance, string modId, bool verboseLogging)
|
||||
public static IDisposable TryAttachEventBusInstance(Type modType, object modInstance,
|
||||
string modId, bool verboseLogging)
|
||||
{
|
||||
if (!HasAttribute(modType, "ShrinkEventBus.EventBusSubscriberAttribute", "ShrinkEventBus.Runtime"))
|
||||
return;
|
||||
if (modInstance is not IShrinkGeneratedSubscriber)
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
var eventBusType = FindType("ShrinkEventBus.EventBus", "ShrinkEventBus.Runtime");
|
||||
var autoRegisterMethod = eventBusType?.GetMethod("AutoRegister",
|
||||
BindingFlags.Public | BindingFlags.Static,
|
||||
null,
|
||||
new[] { typeof(object) },
|
||||
null);
|
||||
if (autoRegisterMethod == null)
|
||||
return;
|
||||
|
||||
autoRegisterMethod.Invoke(null, new[] { modInstance });
|
||||
var busKey = ShrinkBusKey.Mod(modId);
|
||||
EventBus.GetOrCreateBus(busKey, ShrinkBusOptions.DedicatedThread());
|
||||
var binding = EventBus.Attach(modInstance, busKey);
|
||||
if (verboseLogging)
|
||||
Debug.Log($"[ShrinkModFramework] 模组 {modId} 已接入 ShrinkEventBus 实例订阅。");
|
||||
return binding;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogWarning($"[ShrinkModFramework] 模组 {modId} 接入 ShrinkEventBus 失败:{ex.Message}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user