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:
@@ -6,6 +6,7 @@ using ShrinkNetwork;
|
||||
using ShrinkNetwork.Integration;
|
||||
using UnityEngine;
|
||||
|
||||
[ShrinkEventSubscriber(OwnerId = "shrink.demo.embedded-host", DefaultBus = "game")]
|
||||
public sealed class ShrinkEmbeddedHostNetworkDemoSceneController : MonoBehaviour
|
||||
{
|
||||
private const long DemoSessionId = 1;
|
||||
@@ -29,6 +30,7 @@ public sealed class ShrinkEmbeddedHostNetworkDemoSceneController : MonoBehaviour
|
||||
private string _lastSkillDecision = "未请求";
|
||||
private Vector2 _logScroll;
|
||||
private bool _initialized;
|
||||
private IDisposable _eventBinding;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
@@ -45,7 +47,7 @@ public sealed class ShrinkEmbeddedHostNetworkDemoSceneController : MonoBehaviour
|
||||
{
|
||||
ShutdownDemo();
|
||||
ResetState();
|
||||
RegisterEventHandlers();
|
||||
_eventBinding = EventBus.Attach(this);
|
||||
SetupEmbeddedHostTopology();
|
||||
_initialized = true;
|
||||
AppendLog("演示已就绪:本地客户端已接入内置 Host Server。");
|
||||
@@ -137,12 +139,6 @@ public sealed class ShrinkEmbeddedHostNetworkDemoSceneController : MonoBehaviour
|
||||
_logScroll = Vector2.zero;
|
||||
}
|
||||
|
||||
private void RegisterEventHandlers()
|
||||
{
|
||||
EventBus.RegisterEvent<DemoPlayerHpDeltaEvent>(OnEmbeddedHostHpDelta, EventPriority.NORMAL);
|
||||
EventBus.RegisterEvent<DemoCanUseSkillEvent>(OnEmbeddedHostSkillRequest, EventPriority.HIGH);
|
||||
}
|
||||
|
||||
private void SetupEmbeddedHostTopology()
|
||||
{
|
||||
_embeddedHostService = new ShrinkNetworkService(new ShrinkJsonNetworkSerializer(),
|
||||
@@ -164,7 +160,8 @@ public sealed class ShrinkEmbeddedHostNetworkDemoSceneController : MonoBehaviour
|
||||
|
||||
private void ShutdownDemo()
|
||||
{
|
||||
EventBus.UnregisterAllEventsForObject(this);
|
||||
_eventBinding?.Dispose();
|
||||
_eventBinding = null;
|
||||
|
||||
if (_localClientTransport != null)
|
||||
{
|
||||
@@ -285,6 +282,7 @@ public sealed class ShrinkEmbeddedHostNetworkDemoSceneController : MonoBehaviour
|
||||
AppendLog($"客户端收到裁决:{outcome.Result},Canceled={outcome.IsCanceled},Host 法力={_hostMana}。");
|
||||
}
|
||||
|
||||
[ShrinkSubscribe]
|
||||
private void OnEmbeddedHostHpDelta(DemoPlayerHpDeltaEvent evt)
|
||||
{
|
||||
if (evt.TargetNode != DemoNetworkNodeRole.EmbeddedHost)
|
||||
@@ -295,6 +293,7 @@ public sealed class ShrinkEmbeddedHostNetworkDemoSceneController : MonoBehaviour
|
||||
AppendLog($"内置 Host 已应用血量增量 v{evt.DeltaVersion}:hp={evt.Hp}。");
|
||||
}
|
||||
|
||||
[ShrinkSubscribe(Priority = ShrinkEventPriority.High)]
|
||||
private void OnEmbeddedHostSkillRequest(DemoCanUseSkillEvent evt)
|
||||
{
|
||||
if (evt.TargetNode != DemoNetworkNodeRole.EmbeddedHost)
|
||||
@@ -330,7 +329,7 @@ public enum DemoNetworkNodeRole
|
||||
|
||||
[ShrinkNetworkEvent]
|
||||
[ShrinkNetworkMessage(3401, "demo/player_hp_delta")]
|
||||
public sealed class DemoPlayerHpDeltaEvent : EventBase, IShrinkNetworkMessage, IShrinkNetworkDeltaEvent
|
||||
public sealed class DemoPlayerHpDeltaEvent : IShrinkEvent, IShrinkNetworkMessage, IShrinkNetworkDeltaEvent
|
||||
{
|
||||
public DemoNetworkNodeRole TargetNode { get; set; }
|
||||
public string PlayerId { get; set; } = "";
|
||||
@@ -339,14 +338,20 @@ public sealed class DemoPlayerHpDeltaEvent : EventBase, IShrinkNetworkMessage, I
|
||||
public string DeltaKey => $"{TargetNode}:{PlayerId}";
|
||||
}
|
||||
|
||||
[Cancelable]
|
||||
[HasResult]
|
||||
[ShrinkNetworkEvent]
|
||||
[ShrinkNetworkMessage(3410, "demo/can_use_skill")]
|
||||
public sealed class DemoCanUseSkillEvent : EventBase, IShrinkNetworkRequest
|
||||
public sealed class DemoCanUseSkillEvent : IShrinkCancelableEvent,
|
||||
IShrinkResultEvent<EventResult>, IShrinkNetworkRequest
|
||||
{
|
||||
private bool _isCanceled;
|
||||
private EventResult _result = EventResult.DEFAULT;
|
||||
|
||||
public DemoNetworkNodeRole TargetNode { get; set; }
|
||||
public string PlayerId { get; set; } = "";
|
||||
public string SkillId { get; set; } = "";
|
||||
public int ManaCost { get; set; }
|
||||
public bool IsCanceled => _isCanceled;
|
||||
public EventResult Result => _result;
|
||||
public void SetCanceled(bool value) => _isCanceled = value;
|
||||
public void SetResult(EventResult result) => _result = result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user