diff --git a/packages/org.gamecult.eve.unity-scene/Runtime/CultMesh/EveUnityCultMeshPlayableWorldProvider.cs b/packages/org.gamecult.eve.unity-scene/Runtime/CultMesh/EveUnityCultMeshPlayableWorldProvider.cs index 702c142..a9e263c 100644 --- a/packages/org.gamecult.eve.unity-scene/Runtime/CultMesh/EveUnityCultMeshPlayableWorldProvider.cs +++ b/packages/org.gamecult.eve.unity-scene/Runtime/CultMesh/EveUnityCultMeshPlayableWorldProvider.cs @@ -70,17 +70,9 @@ namespace GameCult.Eve.UnityScene } } - public event Action? DocumentAvailable - { - add { Bridge.DocumentAvailable += value; } - remove { Bridge.DocumentAvailable -= value; } - } + public event Action? DocumentAvailable; - public event Action? ReceiptAvailable - { - add { Bridge.ReceiptAvailable += value; } - remove { Bridge.ReceiptAvailable -= value; } - } + public event Action? ReceiptAvailable; public void Configure( string endpoint, @@ -163,6 +155,11 @@ namespace GameCult.Eve.UnityScene private void OnDestroy() { + if (_bridge != null) + { + _bridge.DocumentAvailable -= ForwardDocument; + _bridge.ReceiptAvailable -= ForwardReceipt; + } _bridge?.Dispose(); _transport?.Dispose(); while (_pendingEntityViews.TryDequeue(out var pending)) pending.Lease.Dispose(); @@ -230,9 +227,17 @@ namespace GameCult.Eve.UnityScene _transport.EntityViewAvailable += (view, lease) => _pendingEntityViews.Enqueue(new EntityViewLease(view, lease)); _transport.FieldsSplatsAvailable += fields => _pendingFields.Enqueue(fields); _bridge = new EveUnitySceneLiveProviderBridge(_transport); + _bridge.DocumentAvailable += ForwardDocument; + _bridge.ReceiptAvailable += ForwardReceipt; TraceStartup($"transport-construction {elapsed.Elapsed.TotalMilliseconds:0.###}ms"); } + private void ForwardDocument(EveUnitySceneProviderSurfaceDocument document) => + DocumentAvailable?.Invoke(document); + + private void ForwardReceipt(EveUnitySceneCommandReceipt receipt) => + ReceiptAvailable?.Invoke(receipt); + private static void TraceStartup(string message) { if (string.Equals(Environment.GetEnvironmentVariable("EVEUNITY_TRACE_STARTUP_PHASES"), "1", StringComparison.Ordinal)) diff --git a/packages/org.gamecult.eve.unity-scene/Tests/Editor/EveUnityCultMeshAssetLookupTests.cs b/packages/org.gamecult.eve.unity-scene/Tests/Editor/EveUnityCultMeshAssetLookupTests.cs index f58e0d4..ddc3e21 100644 --- a/packages/org.gamecult.eve.unity-scene/Tests/Editor/EveUnityCultMeshAssetLookupTests.cs +++ b/packages/org.gamecult.eve.unity-scene/Tests/Editor/EveUnityCultMeshAssetLookupTests.cs @@ -52,6 +52,21 @@ namespace GameCult.Eve.UnityScene.Tests } } + [Test] + public void ProviderSubscriptionsDoNotDependOnPreparedTransportLifetime() + { + var gameObject = new GameObject("unprepared-eve-provider-subscriptions"); + var provider = gameObject.AddComponent(); + Action documentHandler = _ => { }; + Action receiptHandler = _ => { }; + + Assert.DoesNotThrow(() => provider.DocumentAvailable += documentHandler); + Assert.DoesNotThrow(() => provider.ReceiptAvailable += receiptHandler); + Assert.DoesNotThrow(() => provider.DocumentAvailable -= documentHandler); + Assert.DoesNotThrow(() => provider.ReceiptAvailable -= receiptHandler); + Assert.DoesNotThrow(() => UnityEngine.Object.DestroyImmediate(gameObject)); + } + [Test] public void ResolvesUnityNormalizedBundleNamesWithoutChangingLogicalAssetIdentity() { diff --git a/packages/org.gamecult.eve.unity-scene/package.json b/packages/org.gamecult.eve.unity-scene/package.json index afe87df..4e417cf 100644 --- a/packages/org.gamecult.eve.unity-scene/package.json +++ b/packages/org.gamecult.eve.unity-scene/package.json @@ -1,7 +1,7 @@ { "name": "org.gamecult.eve.unity-scene", "displayName": "Eve Unity Scene Lowering", - "version": "0.3.101", + "version": "0.3.102", "unity": "6000.0", "description": "Provider-agnostic Unity scene shell for gamecult.eve.surface.v1 interactive world surfaces.", "dependencies": {