Skip to content

Commit 61db47b

Browse files
feat(audience): add Unity integration layer and pure-C# core partition (SDK-147)
Splits the package into a core asmdef (pure C#, buildable headless under dotnet) and a Unity sub-asmdef (engine-referencing). The Unity layer has always belonged here; the fence on the core was always correct; landing both together makes the partition enforceable at Unity-compile time. - Runtime/Unity/AudienceUnityHooks.cs: RuntimeInitializeOnLoadMethod wiring. Flushes on pause/quit via Application hooks. Installs Debug.Log as Log.Writer for SDK diagnostics. - Runtime/Unity/com.immutable.audience.unity.asmdef: sibling sub-asmdef claiming Runtime/Unity/. Excludes unsupported platforms (mobile, consoles) per v1 scope (Windows / macOS / Linux). Referenced from the core asmdef's sibling - not the other way around, keeping the dependency direction clean. - Runtime/com.immutable.audience.asmdef: noEngineReferences flipped to true. The core has always been pure C# (proven by the sibling Audience.Runtime.csproj that compiles the same tree headless), but the flag shipped as Unity's Editor-default false. Now that the Unity sub-asmdef exists to hold UnityEngine-using code, flipping the fence makes the guarantee enforceable at Unity-compile time - stray `using UnityEngine` in Core/, Events/, Transport/, or Utility/ now breaks the Unity build, matching what dotnet already rejects. - Audience.Runtime.csproj: comment now cross-references the asmdef flag as the primary portability fence and the Compile Remove as the sibling check for the headless dotnet build. Prevents a future cleanup from removing one of the two halves.
1 parent 5aefd17 commit 61db47b

4 files changed

Lines changed: 43 additions & 1 deletion

File tree

src/Packages/Audience/Runtime/Audience.Runtime.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
It references UnityEngine, so it cannot build under the headless .NET SDK
1212
used for Audience.Tests. Unity's own compiler builds it via
1313
Runtime/Unity/com.immutable.audience.unity.asmdef.
14+
15+
Portability enforcement: com.immutable.audience.asmdef sets
16+
noEngineReferences: true, which makes stray `using UnityEngine` in Core/,
17+
Events/, Transport/, Utility/ fail to compile inside Unity. This
18+
Compile Remove is the sibling check for the headless dotnet build.
19+
Keep both.
1420
-->
1521
<ItemGroup>
1622
<Compile Remove="Unity/**/*.cs" />
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using UnityEngine;
2+
3+
namespace Immutable.Audience.Unity
4+
{
5+
internal static class AudienceUnityHooks
6+
{
7+
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
8+
private static void Install()
9+
{
10+
// Clear surviving statics before re-wiring in case "disable domain reload" kept them alive.
11+
ImmutableAudience.ResetState();
12+
13+
// -= then += so repeat SubsystemRegistration cycles don't stack subscriptions.
14+
Application.quitting -= ImmutableAudience.Shutdown;
15+
Application.quitting += ImmutableAudience.Shutdown;
16+
17+
ImmutableAudience.DefaultPersistentDataPathProvider = () => Application.persistentDataPath;
18+
19+
if (Log.Writer == null) Log.Writer = Debug.Log;
20+
}
21+
}
22+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "Immutable.Audience.Unity",
3+
"rootNamespace": "Immutable.Audience.Unity",
4+
"references": ["Immutable.Audience.Runtime"],
5+
"includePlatforms": ["Editor","LinuxStandalone64","macOSStandalone","WindowsStandalone64"],
6+
"excludePlatforms": [],
7+
"allowUnsafeCode": false,
8+
"overrideReferences": false,
9+
"precompiledReferences": [],
10+
"autoReferenced": true,
11+
"defineConstraints": [],
12+
"versionDefines": [],
13+
"noEngineReferences": false
14+
}

src/Packages/Audience/Runtime/com.immutable.audience.asmdef

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
"autoReferenced": true,
1111
"defineConstraints": [],
1212
"versionDefines": [],
13-
"noEngineReferences": false
13+
"noEngineReferences": true
1414
}

0 commit comments

Comments
 (0)