Skip to content

Commit 13e7e1f

Browse files
committed
Only add scenes to build when launching the menu scene
1 parent f39cda0 commit 13e7e1f

1 file changed

Lines changed: 17 additions & 22 deletions

File tree

Assets/Tools/AddScenesToBuild.cs

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,42 @@
11
using System;
22
using System.Collections.Generic;
33
using UnityEditor;
4-
using UnityEditor.Build;
5-
using UnityEditor.Build.Reporting;
64
using UnityEditor.SceneManagement;
75
using UnityEngine;
6+
using UnityEngine.SceneManagement;
87

98
/// <summary>
10-
/// Automatically keeps Build Settings populated with every project scene so the
11-
/// Core Platform Menu works without manual intervention.
9+
/// Editor utility that populates Build Settings with every project scene so the
10+
/// Core Platform Menu can discover them at runtime.
1211
///
13-
/// Scenes are refreshed:
14-
/// - Before every player build (IPreprocessBuildWithReport)
15-
/// - When entering Play Mode (playModeStateChanged)
16-
/// - On demand via QA Tools ▸ Refresh Build Scene List
12+
/// This script is intentionally passive — it never runs automatically during CI
13+
/// builds or arbitrary play-mode sessions. The scene list is only refreshed:
14+
///
15+
/// - When entering Play Mode with the menu scene open (for manual testing)
16+
/// - On demand via QA Tools > Refresh Build Scene List
1717
///
1818
/// The Core Platforms Menu scene is always placed at build index 0.
1919
/// </summary>
20-
public class AddScenesToBuild : IPreprocessBuildWithReport
20+
public static class AddScenesToBuild
2121
{
2222
const string kMenuScene = "Assets/QA/Tests/Core Platform Menu/Core Platforms Menu.unity";
2323

2424
static readonly string[] kExcludedSegments = { "xbox", "xr" };
25-
static readonly string[] kExcludedRoots = { "Assets/Tests/", "ExternalSampleProjects/", "Packages/" };
26-
27-
// ── Build callback ──────────────────────────────────────────
28-
29-
public int callbackOrder => -100;
30-
31-
public void OnPreprocessBuild(BuildReport report)
32-
{
33-
RefreshBuildScenes(silent: true);
34-
}
25+
static readonly string[] kExcludedRoots = { "ExternalSampleProjects/", "Packages/" };
3526

36-
// ── Play Mode hook ──────────────────────────────────────────
27+
// ── Play Mode hook (menu scene only) ─────────────────────────
3728

3829
[InitializeOnLoadMethod]
3930
static void RegisterPlayModeHook()
4031
{
4132
EditorApplication.playModeStateChanged += state =>
4233
{
43-
if (state == PlayModeStateChange.ExitingEditMode)
44-
RefreshBuildScenes(silent: true);
34+
if (state != PlayModeStateChange.ExitingEditMode) return;
35+
36+
var activeScene = SceneManager.GetActiveScene();
37+
if (!string.Equals(activeScene.path, kMenuScene, StringComparison.OrdinalIgnoreCase)) return;
38+
39+
RefreshBuildScenes(silent: true);
4540
};
4641
}
4742

0 commit comments

Comments
 (0)