-
Notifications
You must be signed in to change notification settings - Fork 321
/
Copy pathAddScenesToBuild.cs
104 lines (92 loc) · 3.72 KB
/
AddScenesToBuild.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using System;
[InitializeOnLoad]
public class AddScenesToBuild : EditorWindow
{
private const string corePlatformsMenu = "Assets/QA/Tests/Core Platform Menu/Core Platforms Menu.unity";
[MenuItem("QA Tools/Open Core Scene Menu")]
static void OpenScene()
{
EditorSceneManager.OpenScene(corePlatformsMenu);
}
[MenuItem("QA Tools/Add All Core Samples to Build")]
private static void AddAllScenesToBuildExcludingXboxAndXR()
{
// Get all available scenes in the project
string[] sceneGuids = AssetDatabase.FindAssets("t:Scene");
string[] scenePaths = new string[sceneGuids.Length];
for (int i = 0; i < sceneGuids.Length; i++)
{
scenePaths[i] = AssetDatabase.GUIDToAssetPath(sceneGuids[i]);
}
// Filter out scenes in folders containing "xbox" or "xr"
List<string> filteredScenePaths = new List<string>();
string coreScene = null;
// Find the corePlatformsMenu scene and remove it from the general scene list
for (int i = 0; i < scenePaths.Length; i++)
{
if (scenePaths[i] == corePlatformsMenu)
{
coreScene = scenePaths[i];
}
else if (!IsPathInExcludedFolder(scenePaths[i]))
{
filteredScenePaths.Add(scenePaths[i]);
}
}
// Add and ensure "Core Platforms Menu" is at the beginning of the list
if (!string.IsNullOrEmpty(coreScene))
{
filteredScenePaths.Insert(0, coreScene);
}
// Update the build settings
EditorBuildSettingsScene[] buildScenes = new EditorBuildSettingsScene[filteredScenePaths.Count];
for (int i = 0; i < filteredScenePaths.Count; i++)
{
buildScenes[i] = new EditorBuildSettingsScene(filteredScenePaths[i], true);
}
EditorBuildSettings.scenes = buildScenes;
Debug.Log("All scenes (excluding Xbox and XR) added to build settings.");
}
private static bool IsPathInExcludedFolder(string path)
{
// Specify folder names to exclude
string[] excludedFolders = { "xbox", "xr" };
// Check if the path or any part of it contains any of the excluded folder names
foreach (string folder in excludedFolders)
{
if (path.Contains(folder, StringComparison.InvariantCultureIgnoreCase))
{
return true;
}
}
return false;
}
private static void SaveBuildSettings()
{
// Save the current build settings to EditorPrefs
int sceneCount = EditorBuildSettings.scenes.Length;
EditorPrefs.SetInt("BuildSettingsSceneCount", sceneCount);
for (int i = 0; i < sceneCount; i++)
{
EditorPrefs.SetString($"BuildSettingsScenePath_{i}", EditorBuildSettings.scenes[i].path);
EditorPrefs.SetBool($"BuildSettingsSceneEnabled_{i}", EditorBuildSettings.scenes[i].enabled);
}
}
private static void RestoreBuildSettings()
{
// Restore the build settings from EditorPrefs
int sceneCount = EditorPrefs.GetInt("BuildSettingsSceneCount", 0);
EditorBuildSettingsScene[] buildScenes = new EditorBuildSettingsScene[sceneCount];
for (int i = 0; i < sceneCount; i++)
{
string scenePath = EditorPrefs.GetString($"BuildSettingsScenePath_{i}", "");
bool sceneEnabled = EditorPrefs.GetBool($"BuildSettingsSceneEnabled_{i}", false);
buildScenes[i] = new EditorBuildSettingsScene(scenePath, sceneEnabled);
}
EditorBuildSettings.scenes = buildScenes;
}
}