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:
@@ -0,0 +1,48 @@
|
||||
#nullable enable
|
||||
|
||||
using System.Collections;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace ShrinkEventBus.PlayMode.Tests
|
||||
{
|
||||
internal readonly struct MonoLifecycleEvent : IShrinkEvent
|
||||
{
|
||||
public MonoLifecycleEvent(int value) => Value = value;
|
||||
public int Value { get; }
|
||||
}
|
||||
|
||||
[ShrinkEventSubscriber(DefaultBus = "game")]
|
||||
internal sealed class MonoLifecycleTarget : MonoBehaviour
|
||||
{
|
||||
public int Sum { get; private set; }
|
||||
|
||||
[ShrinkSubscribe]
|
||||
private void OnEvent(MonoLifecycleEvent value) => Sum += value.Value;
|
||||
}
|
||||
|
||||
public sealed class ShrinkMonoEventScopePlayModeTests
|
||||
{
|
||||
[UnityTest]
|
||||
public IEnumerator OnEnableAttachesAndOnDisableReleases()
|
||||
{
|
||||
var gameObject = new GameObject("ShrinkMonoEventScope-PlayMode");
|
||||
gameObject.SetActive(false);
|
||||
var target = gameObject.AddComponent<MonoLifecycleTarget>();
|
||||
gameObject.AddComponent<ShrinkMonoEventScope>();
|
||||
|
||||
gameObject.SetActive(true);
|
||||
yield return null;
|
||||
yield return EventBus.PostAsync(new MonoLifecycleEvent(3)).ToCoroutine();
|
||||
Assert.AreEqual(3, target.Sum);
|
||||
|
||||
gameObject.SetActive(false);
|
||||
yield return null;
|
||||
yield return EventBus.PostAsync(new MonoLifecycleEvent(5)).ToCoroutine();
|
||||
Assert.AreEqual(3, target.Sum);
|
||||
Object.Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user