|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
3 | 3 | using UnityEditor; |
4 | | -using UnityEditor.Build; |
5 | | -using UnityEditor.Build.Reporting; |
6 | 4 | using UnityEditor.SceneManagement; |
7 | 5 | using UnityEngine; |
| 6 | +using UnityEngine.SceneManagement; |
8 | 7 |
|
9 | 8 | /// <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. |
12 | 11 | /// |
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 |
17 | 17 | /// |
18 | 18 | /// The Core Platforms Menu scene is always placed at build index 0. |
19 | 19 | /// </summary> |
20 | | -public class AddScenesToBuild : IPreprocessBuildWithReport |
| 20 | +public static class AddScenesToBuild |
21 | 21 | { |
22 | 22 | const string kMenuScene = "Assets/QA/Tests/Core Platform Menu/Core Platforms Menu.unity"; |
23 | 23 |
|
24 | 24 | 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/" }; |
35 | 26 |
|
36 | | - // ── Play Mode hook ────────────────────────────────────────── |
| 27 | + // ── Play Mode hook (menu scene only) ───────────────────────── |
37 | 28 |
|
38 | 29 | [InitializeOnLoadMethod] |
39 | 30 | static void RegisterPlayModeHook() |
40 | 31 | { |
41 | 32 | EditorApplication.playModeStateChanged += state => |
42 | 33 | { |
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); |
45 | 40 | }; |
46 | 41 | } |
47 | 42 |
|
|
0 commit comments