feat: make Unity integration optional

This commit is contained in:
cneicy committed 2026-10-03 23:36:43 +08:00
1 parent a92c9d2cea
commit 240d24ba7a
27 files changed
+916 -69

No files matched your search

+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: eae196d52d4a4091bdf0aa90888b6c97
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,19 @@
{
"name": "ShrinkEventBus.Integration.Runtime",
"rootNamespace": "ShrinkEventBus.Integration",
"references": [
"ShrinkEventBus.Runtime",
"ShrinkRuntime.Abstractions"
],
"autoReferenced": true,
"defineConstraints": [
"SHRINK_EVENTBUS_HAS_SHARED_RUNTIME"
],
"versionDefines": [
{
"name": "com.cneicy.shrink-runtime-abstractions",
"expression": "0.1.0",
"define": "SHRINK_EVENTBUS_HAS_SHARED_RUNTIME"
}
]
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 86c48423db2e41e1b208c468296b7faf
@@ -0,0 +1,20 @@
#if SHRINK_EVENTBUS_HAS_SHARED_RUNTIME
using System;
using ShrinkSDK.Runtime;
namespace ShrinkEventBus.Integration
{
public sealed class ShrinkSharedMainThreadDispatcher : IShrinkEventBusMainThreadDispatcher
{
private readonly IShrinkMainThreadDispatcher _dispatcher;
public ShrinkSharedMainThreadDispatcher(IShrinkMainThreadDispatcher dispatcher)
{
_dispatcher = dispatcher ?? throw new ArgumentNullException(nameof(dispatcher));
}
public bool IsMainThread => _dispatcher.IsMainThread;
public bool TryPost(Action action) => _dispatcher.TryPost(action);
}
}
#endif
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: f818313cb4e3447f9622b71decefa86c
+5
View File
@@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: bc17b8a03b8d4abe8068d9310fe12f19
folderAsset: yes
DefaultImporter:
externalObjects: {}
@@ -0,0 +1,43 @@
#if SHRINK_EVENTBUS_HAS_SHARED_RUNTIME
using System;
using NUnit.Framework;
using ShrinkSDK.Runtime;
namespace ShrinkEventBus.Integration.Tests
{
public sealed class SharedDispatcherTests
{
private sealed class Dispatcher : IShrinkMainThreadDispatcher
{
public bool IsMainThread => false;
public Action Pending;
public bool TryPost(Action action) { Pending = action; return true; }
}
[Test]
public void AdapterPreservesAffinityAndPostsThroughSharedDispatcher()
{
var original = ShrinkEventBusRuntime.MainThreadDispatcher;
try
{
var dispatcher = new Dispatcher();
var adapter = new ShrinkSharedMainThreadDispatcher(dispatcher);
ShrinkEventBusRuntime.ConfigureMainThreadDispatcher(adapter);
Assert.IsFalse(ShrinkEventBusRuntime.MainThreadDispatcher.IsMainThread);
var hits = 0;
Assert.IsTrue(ShrinkEventBusRuntime.MainThreadDispatcher.TryPost(() => hits++));
Assert.AreEqual(0, hits);
dispatcher.Pending();
Assert.AreEqual(1, hits);
}
finally { ShrinkEventBusRuntime.ConfigureMainThreadDispatcher(original); }
}
[Test]
public void AdapterRejectsNullDispatcher()
{
Assert.Throws<ArgumentNullException>(() => new ShrinkSharedMainThreadDispatcher(null));
}
}
}
#endif
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 87e04bff7dc943dd9a8205b37e631c19
@@ -0,0 +1,26 @@
{
"name": "ShrinkEventBus.Integration.Runtime.Tests",
"references": [
"ShrinkEventBus.Runtime",
"ShrinkEventBus.Integration.Runtime",
"ShrinkRuntime.Abstractions"
],
"includePlatforms": [
"Editor"
],
"optionalUnityReferences": [
"TestAssemblies"
],
"autoReferenced": false,
"defineConstraints": [
"UNITY_INCLUDE_TESTS",
"SHRINK_EVENTBUS_HAS_SHARED_RUNTIME"
],
"versionDefines": [
{
"name": "com.cneicy.shrink-runtime-abstractions",
"expression": "0.1.0",
"define": "SHRINK_EVENTBUS_HAS_SHARED_RUNTIME"
}
]
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 4062d02e94ea4577957d4185688d1454