Skip to content

Commit 6a44f72

Browse files
feat(audience): normalize platform wire values, add isEditor (SDK-343)
- platform now sends Windows, macOS, Linux, iOS, Android. WindowsPlayer/WindowsEditor and OSXPlayer/OSXEditor and LinuxPlayer/LinuxEditor each collapse to one OS string. Studios no longer need LIKE 'Windows%' to filter by OS. - New isEditor bool on game_launch sources from Application.isEditor. Replaces the Player vs Editor signal previously buried inside platform, so studios can filter dev runs cleanly. - Unmapped RuntimePlatform values (console, WebGL, server builds) still fall back to the raw enum string so console traffic is not silently dropped. - osFamily is intentionally left as the raw SystemInfo.operatingSystemFamily value (Windows, MacOSX, Linux, Other), so power users still have direct access to Unity's view. platform is the curated public field; osFamily is the passthrough. - DeviceCollectorTests covers the new platform mappings and isEditor true/false. ImmutableAudienceTests provider example updated to "Windows". Breaking wire-format change. Blocks immutable/documentation#83 (SDK-319). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent d4998a8 commit 6a44f72

3 files changed

Lines changed: 52 additions & 5 deletions

File tree

src/Packages/Audience/Runtime/Unity/DeviceCollector.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,15 @@ internal static Dictionary<string, object> CollectContext()
4747
}
4848

4949
internal static Dictionary<string, object> CollectGameLaunchProperties(
50-
RuntimePlatform? platformOverride = null)
50+
RuntimePlatform? platformOverride = null,
51+
bool? isEditorOverride = null)
5152
{
5253
var platform = platformOverride ?? Application.platform;
54+
var isEditor = isEditorOverride ?? Application.isEditor;
5355
var props = new Dictionary<string, object>
5456
{
5557
["platform"] = PlatformName(platform),
58+
["isEditor"] = isEditor,
5659
["version"] = Truncate(Application.version, 256),
5760
["buildGuid"] = Truncate(Application.buildGUID, 256),
5861
["unityVersion"] = Truncate(Application.unityVersion, 256),
@@ -106,7 +109,11 @@ internal static Dictionary<string, object> CollectGameLaunchProperties(
106109

107110
private static string PlatformName(RuntimePlatform platform) => platform switch
108111
{
112+
RuntimePlatform.WindowsPlayer or RuntimePlatform.WindowsEditor => "Windows",
113+
RuntimePlatform.OSXPlayer or RuntimePlatform.OSXEditor => "macOS",
114+
RuntimePlatform.LinuxPlayer or RuntimePlatform.LinuxEditor => "Linux",
109115
RuntimePlatform.IPhonePlayer => "iOS",
116+
RuntimePlatform.Android => "Android",
110117
_ => platform.ToString(),
111118
};
112119

src/Packages/Audience/Tests/Runtime/ImmutableAudienceTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ public void Init_GameLaunch_IncludesLaunchContextProviderFields()
11871187
{
11881188
ImmutableAudience.LaunchContextProvider = () => new Dictionary<string, object>
11891189
{
1190-
["platform"] = "WindowsPlayer",
1190+
["platform"] = "Windows",
11911191
["version"] = "1.2.3",
11921192
["buildGuid"] = "a1b2c3d4e5f6",
11931193
["unityVersion"] = "2022.3.20f1",
@@ -1201,7 +1201,7 @@ public void Init_GameLaunch_IncludesLaunchContextProviderFields()
12011201
.Select(File.ReadAllText)
12021202
.FirstOrDefault(c => c.Contains("\"game_launch\""));
12031203
Assert.IsNotNull(launchFile, "game_launch should have been enqueued");
1204-
StringAssert.Contains("\"platform\":\"WindowsPlayer\"", launchFile);
1204+
StringAssert.Contains("\"platform\":\"Windows\"", launchFile);
12051205
StringAssert.Contains("\"version\":\"1.2.3\"", launchFile);
12061206
StringAssert.Contains("\"buildGuid\":\"a1b2c3d4e5f6\"", launchFile);
12071207
StringAssert.Contains("\"unityVersion\":\"2022.3.20f1\"", launchFile);

src/Packages/Audience/Tests/Runtime/Unity/DeviceCollectorTests.cs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void CollectGameLaunchProperties_AlwaysContainsCrossPlatformFields()
5252
{
5353
var props = DeviceCollector.CollectGameLaunchProperties();
5454
foreach (var key in new[] {
55-
"platform", "version", "buildGuid", "unityVersion",
55+
"platform", "isEditor", "version", "buildGuid", "unityVersion",
5656
"osFamily", "deviceModel", "gpu", "gpuVendor",
5757
"cpu", "cpuCores", "ramMb" })
5858
{
@@ -134,11 +134,51 @@ public void CollectGameLaunchProperties_NonIOS_DoesNotContainIdfv()
134134
}
135135

136136
[Test]
137-
public void CollectGameLaunchProperties_iOS_ContainsPlatformIPhonePlayer()
137+
public void CollectGameLaunchProperties_iOS_PlatformIsIOS()
138138
{
139139
IDFVBridge.Impl = () => null;
140140
var props = DeviceCollector.CollectGameLaunchProperties(RuntimePlatform.IPhonePlayer);
141141
Assert.AreEqual("iOS", props["platform"]);
142142
}
143+
144+
// -----------------------------------------------------------------
145+
// PlatformName mapping: collapse Player/Editor variants to OS name
146+
// -----------------------------------------------------------------
147+
148+
[TestCase(RuntimePlatform.WindowsPlayer, "Windows")]
149+
[TestCase(RuntimePlatform.WindowsEditor, "Windows")]
150+
[TestCase(RuntimePlatform.OSXPlayer, "macOS")]
151+
[TestCase(RuntimePlatform.OSXEditor, "macOS")]
152+
[TestCase(RuntimePlatform.LinuxPlayer, "Linux")]
153+
[TestCase(RuntimePlatform.LinuxEditor, "Linux")]
154+
[TestCase(RuntimePlatform.IPhonePlayer, "iOS")]
155+
[TestCase(RuntimePlatform.Android, "Android")]
156+
public void CollectGameLaunchProperties_Platform_MapsToLaymanName(
157+
RuntimePlatform input, string expected)
158+
{
159+
var props = DeviceCollector.CollectGameLaunchProperties(input);
160+
Assert.AreEqual(expected, props["platform"]);
161+
}
162+
163+
[Test]
164+
public void CollectGameLaunchProperties_Platform_UnmappedFallsBackToEnumName()
165+
{
166+
// Console / unsupported targets must not be silently dropped.
167+
var props = DeviceCollector.CollectGameLaunchProperties(RuntimePlatform.WebGLPlayer);
168+
Assert.AreEqual("WebGLPlayer", props["platform"]);
169+
}
170+
171+
// -----------------------------------------------------------------
172+
// isEditor: distinguishes dev runs from production player traffic
173+
// -----------------------------------------------------------------
174+
175+
[TestCase(true)]
176+
[TestCase(false)]
177+
public void CollectGameLaunchProperties_IsEditor_ReflectsOverride(bool isEditor)
178+
{
179+
var props = DeviceCollector.CollectGameLaunchProperties(
180+
isEditorOverride: isEditor);
181+
Assert.AreEqual(isEditor, props["isEditor"]);
182+
}
143183
}
144184
}

0 commit comments

Comments
 (0)