public void Setup(string rootImageTemplatePath)
        {
            ColorSpace      colorSpace;
            BuildTarget     buildPlatform;
            RuntimePlatform runtimePlatform;

            GraphicsDeviceType[] graphicsDevices;

            // Figure out if we're preparing to run in Editor playmode, or if we're building to run outside the Editor
            if (IsBuildingForEditorPlaymode)
            {
                colorSpace      = QualitySettings.activeColorSpace;
                buildPlatform   = BuildTarget.NoTarget;
                runtimePlatform = Application.platform;
                graphicsDevices = new[] { SystemInfo.graphicsDeviceType };
            }
            else
            {
                buildPlatform   = EditorUserBuildSettings.activeBuildTarget;
                runtimePlatform = Utils.BuildTargetToRuntimePlatform(buildPlatform);
                colorSpace      = PlayerSettings.colorSpace;
                graphicsDevices = PlayerSettings.GetGraphicsAPIs(buildPlatform);
            }

            var bundleBuilds = new List <AssetBundleBuild>();

            foreach (var api in graphicsDevices)
            {
                var images = EditorGraphicsTestCaseProvider.CollectReferenceImagePathsFor(rootImageTemplatePath, colorSpace, runtimePlatform, api);

                Utils.SetupReferenceImageImportSettings(images.Values);

                if (buildPlatform == BuildTarget.NoTarget)
                {
                    continue;
                }

                bundleBuilds.Add(new AssetBundleBuild
                {
                    assetBundleName  = string.Format("referenceimages-{0}-{1}-{2}", colorSpace, runtimePlatform, api),
                    addressableNames = images.Keys.ToArray(),
                    assetNames       = images.Values.ToArray()
                });
            }

            if (bundleBuilds.Count > 0)
            {
                if (!Directory.Exists("Assets/StreamingAssets"))
                {
                    Directory.CreateDirectory("Assets/StreamingAssets");
                }

                foreach (var bundle in bundleBuilds)
                {
                    BuildPipeline.BuildAssetBundles("Assets/StreamingAssets", new [] { bundle }, BuildAssetBundleOptions.None,
                                                    buildPlatform);
                }
            }


            // For each scene in the build settings, force build of the lightmaps if it has "DoLightmap" label.
            // Note that in the PreBuildSetup stage, TestRunner has already created a new scene with its testing monobehaviours

            Scene trScene = EditorSceneManagement.EditorSceneManager.GetSceneAt(0);

            foreach (EditorBuildSettingsScene scene in EditorBuildSettings.scenes)
            {
                SceneAsset sceneAsset = AssetDatabase.LoadAssetAtPath <SceneAsset>(scene.path);
                var        labels     = new System.Collections.Generic.List <string>(AssetDatabase.GetLabels(sceneAsset));
                if (labels.Contains(bakeLabel))
                {
                    EditorSceneManagement.EditorSceneManager.OpenScene(scene.path, EditorSceneManagement.OpenSceneMode.Additive);

                    Scene currentScene = EditorSceneManagement.EditorSceneManager.GetSceneAt(1);

                    EditorSceneManagement.EditorSceneManager.SetActiveScene(currentScene);

                    Lightmapping.giWorkflowMode = Lightmapping.GIWorkflowMode.OnDemand;

                    Lightmapping.Bake();

                    EditorSceneManagement.EditorSceneManager.SaveScene(currentScene);

                    EditorSceneManagement.EditorSceneManager.SetActiveScene(trScene);

                    EditorSceneManagement.EditorSceneManager.CloseScene(currentScene, true);
                }
            }

            if (!IsBuildingForEditorPlaymode)
            {
                new CreateSceneListFileFromBuildSettings().Setup();
            }
        }
 public void Setup()
 {
     File.WriteAllLines("Assets/StreamingAssets/SceneList.txt", EditorGraphicsTestCaseProvider.GetTestScenePaths());
 }
Exemple #3
0
        public static void Setup(string rootImageTemplatePath = EditorGraphicsTestCaseProvider.ReferenceImagesRoot, string imageResultsPath = "")
        {
            ColorSpace      colorSpace;
            BuildTarget     buildPlatform;
            RuntimePlatform runtimePlatform;

            GraphicsDeviceType[] graphicsDevices;

            string xrsdk = "None";

            UnityEditor.EditorPrefs.SetBool("AsynchronousShaderCompilation", false);

            // Figure out if we're preparing to run in Editor playmode, or if we're building to run outside the Editor
            if (IsBuildingForEditorPlaymode)
            {
                colorSpace      = QualitySettings.activeColorSpace;
                buildPlatform   = BuildTarget.NoTarget;
                runtimePlatform = Application.platform;
                graphicsDevices = new[] { SystemInfo.graphicsDeviceType };

                SetGameViewSize(ImageAssert.kBackBufferWidth, ImageAssert.kBackBufferHeight);
            }
            else
            {
                buildPlatform   = EditorUserBuildSettings.activeBuildTarget;
                runtimePlatform = Utils.BuildTargetToRuntimePlatform(buildPlatform);
                colorSpace      = PlayerSettings.colorSpace;
                graphicsDevices = PlayerSettings.GetGraphicsAPIs(buildPlatform);
            }

#pragma warning disable 0618
#if !UNITY_2020_2_OR_NEWER
            if (PlayerSettings.virtualRealitySupported == true)
            {
                string[] VrSDKs;

                // The NoTarget build target used here when we're in editor mode won't return any xr sdks
                // So just using the Standalone one since that should be what the editor is using.
                if (IsBuildingForEditorPlaymode)
                {
                    VrSDKs = PlayerSettings.GetVirtualRealitySDKs(BuildTargetGroup.Standalone);
                }
                else
                {
                    VrSDKs = PlayerSettings.GetVirtualRealitySDKs(BuildPipeline.GetBuildTargetGroup(buildPlatform));
                }

                // VR can be enabled and no VR platforms listed in the UI.  In that case it will use the non-xr rendering.
                xrsdk = VrSDKs.Length == 0 ? "None" : VrSDKs.First();
            }
#endif

            var xrsettings = XRGeneralSettingsPerBuildTarget.XRGeneralSettingsForBuildTarget(BuildPipeline.GetBuildTargetGroup(buildPlatform));

            // Since the settings are null when using NoTarget for the BuildTargetGroup which editor playmode seems to do
            // just use Standalone settings instead.
            if (IsBuildingForEditorPlaymode)
            {
                xrsettings = XRGeneralSettingsPerBuildTarget.XRGeneralSettingsForBuildTarget(BuildTargetGroup.Standalone);
            }

            if (xrsettings != null && xrsettings.InitManagerOnStart && !RuntimeSettings.reuseTestsForXR)
            {
                if (xrsettings.AssignedSettings.loaders.Count > 0)
                {
                    // since we don't really know which runtime loader will actually be used at runtime,
                    // just take the first one assuming it will work and if it isn't loaded the
                    // tests should fail since the reference images bundle will be named
                    // with a loader that isn't active at runtime.
                    var firstLoader = xrsettings.AssignedSettings.loaders.First();

                    if (firstLoader != null)
                    {
                        xrsdk = firstLoader.name;
                    }
                }
            }

            ImageHandler.instance.ImageResultsPath = imageResultsPath;

            var bundleBuilds = new List <AssetBundleBuild>();

            if (!IsBuildingForEditorPlaymode)
            {
                foreach (var api in graphicsDevices)
                {
                    var images = EditorGraphicsTestCaseProvider.CollectReferenceImagePathsFor(rootImageTemplatePath, colorSpace, runtimePlatform, api, xrsdk);

                    Utils.SetupReferenceImageImportSettings(images.Values);

                    bundleBuilds.Add(new AssetBundleBuild
                    {
                        assetBundleName  = string.Format("referenceimages-{0}-{1}-{2}-{3}", colorSpace, runtimePlatform.ToUniqueString(), api, xrsdk),
                        addressableNames = images.Keys.ToArray(),
                        assetNames       = images.Values.ToArray()
                    });
                }
            }

            if (bundleBuilds.Count > 0)
            {
                if (!Directory.Exists("Assets/StreamingAssets"))
                {
                    Directory.CreateDirectory("Assets/StreamingAssets");
                }

                foreach (var bundle in bundleBuilds)
                {
                    BuildPipeline.BuildAssetBundles("Assets/StreamingAssets", new [] { bundle }, BuildAssetBundleOptions.None,
                                                    buildPlatform);
                }
            }

            // For each scene in the build settings, force build of the lightmaps if it has "DoLightmap" label.
            // Note that in the PreBuildSetup stage, TestRunner has already created a new scene with its testing monobehaviours

            Scene trScene = EditorSceneManagement.EditorSceneManager.GetSceneAt(0);

            string[] selectedScenes = GetSelectedScenes();

            var sceneIndex          = 0;
            var buildSettingsScenes = EditorBuildSettings.scenes;
            var totalScenes         = EditorBuildSettings.scenes.Length;

            var filterGuid = AssetDatabase.FindAssets("t: TestFilters");

            var filterConfigs = AssetDatabase.LoadAssetAtPath <TestFilters>(
                AssetDatabase.GUIDToAssetPath(filterGuid.FirstOrDefault()));

            var filterTest = Resources.Load <TestFilters>("TestCaseFilters");

            foreach (var scene in buildSettingsScenes)
            {
                if (!scene.enabled)
                {
                    continue;
                }

                if (filterConfigs != null)
                {
                    var filtersForScene = new List <TestFilterConfig>();

                    // Right now only single TestFilter.asset file will be processed
                    foreach (var testFilter in filterConfigs.filters)
                    {
                        // legacy support for when test filters only supported one scene.
                        if (testFilter.FilteredScene != null && (testFilter.FilteredScenes == null || !testFilter.FilteredScenes.Any(
                                                                     s => AssetDatabase.GetAssetPath(s) == AssetDatabase.GetAssetPath(testFilter.FilteredScene))))
                        {
                            if (testFilter.FilteredScenes == null)
                            {
                                testFilter.FilteredScenes = new SceneAsset[] { testFilter.FilteredScene };
                            }
                            else
                            {
                                testFilter.FilteredScenes.Concat(new[] { testFilter.FilteredScene }).ToArray();
                            }
                        }

                        foreach (var filteredScene in testFilter.FilteredScenes)
                        {
                            if (AssetDatabase.GetAssetPath(filteredScene) == scene.path)
                            {
                                filtersForScene.Add(testFilter);

                                // If duplicates scenes match we don't need to duplicate the filter in the list.
                                break;
                            }
                        }
                    }

                    // In case more than one filter match the scene, display all the reasons in the output.
                    string filterReasons = string.Empty;

                    foreach (var filter in filtersForScene)
                    {
                        StereoRenderingModeFlags stereoModeFlag = 0;

                        switch (PlayerSettings.stereoRenderingPath)
                        {
                        case StereoRenderingPath.MultiPass:
                            stereoModeFlag |= StereoRenderingModeFlags.MultiPass;
                            break;

                        case StereoRenderingPath.SinglePass:
                            stereoModeFlag |= StereoRenderingModeFlags.SinglePass;
                            break;

                        case StereoRenderingPath.Instancing:
                            stereoModeFlag |= StereoRenderingModeFlags.Instancing;
                            break;
                        }

                        if ((filter.BuildPlatform == buildPlatform || filter.BuildPlatform == BuildTarget.NoTarget) &&
                            (filter.GraphicsDevice == graphicsDevices.First() || filter.GraphicsDevice == GraphicsDeviceType.Null) &&
                            (filter.ColorSpace == colorSpace || filter.ColorSpace == ColorSpace.Uninitialized))
                        {
                            // Non vr filter matched if none of the VR settings are present.
                            if ((!PlayerSettings.virtualRealitySupported || !(xrsettings != null && xrsettings.InitManagerOnStart)) &&
                                (string.IsNullOrEmpty(filter.XrSdk) || string.Compare(filter.XrSdk, "None", true) == 0) &&
                                filter.StereoModes == StereoRenderingModeFlags.None)
                            {
                                scene.enabled  = false;
                                filterReasons += filter.Reason + "\n";
                            }
                            // If VR is enabled then the VR specific filters need to match the filter too.
                            else if ((PlayerSettings.virtualRealitySupported || (xrsettings != null && xrsettings.InitManagerOnStart)) &&
                                     (filter.StereoModes == StereoRenderingModeFlags.None || (filter.StereoModes & stereoModeFlag) == stereoModeFlag) &&
                                     (filter.XrSdk == xrsdk || string.IsNullOrEmpty(filter.XrSdk)))
                            {
                                scene.enabled  = false;
                                filterReasons += filter.Reason + "\n";
                            }
                        }
                    }

                    if (!scene.enabled)
                    {
                        Debug.Log(string.Format("Removed scene {0} from build settings because:\n{1}", Path.GetFileNameWithoutExtension(scene.path), filterReasons));
                    }
                }
#pragma warning restore 0618

                SceneAsset sceneAsset = AssetDatabase.LoadAssetAtPath <SceneAsset>(scene.path);
                var        labels     = new System.Collections.Generic.List <string>(AssetDatabase.GetLabels(sceneAsset));

                // if we successfully retrieved the names of the selected scenes, we filter using this list
                if (selectedScenes.Length > 0 && !selectedScenes.Contains(sceneAsset.name))
                {
                    continue;
                }

                if (labels.Contains(bakeLabel))
                {
                    EditorSceneManagement.EditorSceneManager.OpenScene(scene.path, EditorSceneManagement.OpenSceneMode.Additive);

                    Scene currentScene = EditorSceneManagement.EditorSceneManager.GetSceneAt(1);

                    EditorSceneManagement.EditorSceneManager.SetActiveScene(currentScene);
#pragma warning disable 618
                    Lightmapping.giWorkflowMode = Lightmapping.GIWorkflowMode.OnDemand;
#pragma warning restore 618
                    //EditorUtility.DisplayProgressBar($"Baking Test Scenes {(sceneIndex + 1).ToString()}/{totalScenes.ToString()}", $"Baking {sceneAsset.name}", ((float)sceneIndex / totalScenes));

                    Lightmapping.Bake();

                    EditorSceneManagement.EditorSceneManager.SaveScene(currentScene);

                    EditorSceneManagement.EditorSceneManager.SetActiveScene(trScene);

                    EditorSceneManagement.EditorSceneManager.CloseScene(currentScene, true);
                }
                sceneIndex++;
            }

            // set the scene list in the build settings window.  Only updating the array will do this.
            EditorBuildSettings.scenes = buildSettingsScenes.Where(s => s.enabled).ToArray();

            //EditorUtility.ClearProgressBar();

            if (!IsBuildingForEditorPlaymode)
            {
                new CreateSceneListFileFromBuildSettings().Setup();
            }
        }
        public void Setup()
        {
            ColorSpace      colorSpace;
            BuildTarget     buildPlatform;
            RuntimePlatform runtimePlatform;

            GraphicsDeviceType[] graphicsDevices;

            // Figure out if we're preparing to run in Editor playmode, or if we're building to run outside the Editor
            if (IsBuildingForEditorPlaymode)
            {
                colorSpace      = QualitySettings.activeColorSpace;
                buildPlatform   = BuildTarget.NoTarget;
                runtimePlatform = Application.platform;
                graphicsDevices = new[] { SystemInfo.graphicsDeviceType };
            }
            else
            {
                buildPlatform   = EditorUserBuildSettings.activeBuildTarget;
                runtimePlatform = Utils.BuildTargetToRuntimePlatform(buildPlatform);
                colorSpace      = PlayerSettings.colorSpace;
                graphicsDevices = PlayerSettings.GetGraphicsAPIs(buildPlatform);
            }

            var bundleBuilds = new List <AssetBundleBuild>();

            foreach (var api in graphicsDevices)
            {
                var images = EditorGraphicsTestCaseProvider.CollectReferenceImagePathsFor(colorSpace, runtimePlatform, api);

                Utils.SetupReferenceImageImportSettings(images.Values);

                if (buildPlatform == BuildTarget.NoTarget)
                {
                    continue;
                }

                bundleBuilds.Add(new AssetBundleBuild
                {
                    assetBundleName  = string.Format("referenceimages-{0}-{1}-{2}", colorSpace, runtimePlatform, api),
                    addressableNames = images.Keys.ToArray(),
                    assetNames       = images.Values.ToArray()
                });
            }

            if (bundleBuilds.Count > 0)
            {
                if (!Directory.Exists("Assets/StreamingAssets"))
                {
                    Directory.CreateDirectory("Assets/StreamingAssets");
                }

                foreach (var bundle in bundleBuilds)
                {
                    BuildPipeline.BuildAssetBundles("Assets/StreamingAssets", new [] { bundle }, BuildAssetBundleOptions.None,
                                                    buildPlatform);
                }
            }

            if (!IsBuildingForEditorPlaymode)
            {
                new CreateSceneListFileFromBuildSettings().Setup();
            }
        }
        public void Setup(string rootImageTemplatePath)
        {
            ColorSpace      colorSpace;
            BuildTarget     buildPlatform;
            RuntimePlatform runtimePlatform;

            GraphicsDeviceType[] graphicsDevices;

            UnityEditor.EditorPrefs.SetBool("AsynchronousShaderCompilation", false);

            // Figure out if we're preparing to run in Editor playmode, or if we're building to run outside the Editor
            if (IsBuildingForEditorPlaymode)
            {
                colorSpace      = QualitySettings.activeColorSpace;
                buildPlatform   = BuildTarget.NoTarget;
                runtimePlatform = Application.platform;
                graphicsDevices = new[] { SystemInfo.graphicsDeviceType };
            }
            else
            {
                buildPlatform   = EditorUserBuildSettings.activeBuildTarget;
                runtimePlatform = Utils.BuildTargetToRuntimePlatform(buildPlatform);
                colorSpace      = PlayerSettings.colorSpace;
                graphicsDevices = PlayerSettings.GetGraphicsAPIs(buildPlatform);
            }

            var bundleBuilds = new List <AssetBundleBuild>();

            foreach (var api in graphicsDevices)
            {
                var images = EditorGraphicsTestCaseProvider.CollectReferenceImagePathsFor(rootImageTemplatePath, colorSpace, runtimePlatform, api);

                Utils.SetupReferenceImageImportSettings(images.Values);

                if (buildPlatform == BuildTarget.NoTarget)
                {
                    continue;
                }

                bundleBuilds.Add(new AssetBundleBuild
                {
                    assetBundleName  = string.Format("referenceimages-{0}-{1}-{2}", colorSpace, runtimePlatform, api),
                    addressableNames = images.Keys.ToArray(),
                    assetNames       = images.Values.ToArray()
                });
            }

            if (bundleBuilds.Count > 0)
            {
                if (!Directory.Exists("Assets/StreamingAssets"))
                {
                    Directory.CreateDirectory("Assets/StreamingAssets");
                }

                foreach (var bundle in bundleBuilds)
                {
                    BuildPipeline.BuildAssetBundles("Assets/StreamingAssets", new [] { bundle }, BuildAssetBundleOptions.None,
                                                    buildPlatform);
                }
            }


            // For each scene in the build settings, force build of the lightmaps if it has "DoLightmap" label.
            // Note that in the PreBuildSetup stage, TestRunner has already created a new scene with its testing monobehaviours

            Scene trScene = EditorSceneManagement.EditorSceneManager.GetSceneAt(0);

            string[] selectedScenes = GetSelectedScenes();

            var sceneIndex  = 0;
            var totalScenes = EditorBuildSettings.scenes.Length;

            string[] filterGUIDs = AssetDatabase.FindAssets("t:TestFilters");

            List <TestFilters> filters = new List <TestFilters>();

            foreach (var filterGUID in filterGUIDs)
            {
                string filterPath = AssetDatabase.GUIDToAssetPath(filterGUID);
                filters.Add(AssetDatabase.LoadAssetAtPath(filterPath, typeof(TestFilters)) as TestFilters);
            }
            // Disabling scenes directly in EditorBuildSettings.scenes does not work
            // As a solution - disabling scenes in temporary variable and then assigning it back to EditorBuildSettings.scenes
            EditorBuildSettingsScene[] scenes = EditorBuildSettings.scenes;

            foreach (EditorBuildSettingsScene scene in scenes)
            {
                if (!scene.enabled)
                {
                    continue;
                }

                if (filters.Count > 0)
                {
                    // Right now leaving only single filter available per project.
                    var    filtersForScene = filters.First().filters.Where(f => AssetDatabase.GetAssetPath(f.FilteredScene) == scene.path);
                    bool   enableScene     = true;
                    string filterReasons   = "";

                    foreach (var filter in filtersForScene)
                    {
                        if ((filter.BuildPlatform == buildPlatform || filter.BuildPlatform == BuildTarget.NoTarget) &&
                            (filter.GraphicsDevice == graphicsDevices.First() || filter.GraphicsDevice == GraphicsDeviceType.Null) &&
                            (filter.ColorSpace == colorSpace || filter.ColorSpace == ColorSpace.Uninitialized))
                        {
                            // Adding reasons in case when same test is ignored several times
                            filterReasons += filter.Reason + "\n";
                            enableScene    = false;
                        }
                    }
                    scene.enabled = enableScene;
                    if (!enableScene)
                    {
                        Debug.Log(string.Format("Removed scene {0} from build settings because {1}", Path.GetFileNameWithoutExtension(scene.path), filterReasons));
                        continue;
                    }
                }


                SceneAsset sceneAsset = AssetDatabase.LoadAssetAtPath <SceneAsset>(scene.path);
                var        labels     = new System.Collections.Generic.List <string>(AssetDatabase.GetLabels(sceneAsset));

                // if we successfully retrieved the names of the selected scenes, we filter using this list
                if (selectedScenes.Length > 0 && !selectedScenes.Contains(sceneAsset.name))
                {
                    continue;
                }

                if (labels.Contains(bakeLabel))
                {
                    EditorSceneManagement.EditorSceneManager.OpenScene(scene.path, EditorSceneManagement.OpenSceneMode.Additive);

                    Scene currentScene = EditorSceneManagement.EditorSceneManager.GetSceneAt(1);

                    EditorSceneManagement.EditorSceneManager.SetActiveScene(currentScene);
#pragma warning disable 618
                    Lightmapping.giWorkflowMode = Lightmapping.GIWorkflowMode.OnDemand;
#pragma warning restore 618
                    EditorUtility.DisplayProgressBar($"Baking Test Scenes {(sceneIndex + 1).ToString()}/{totalScenes.ToString()}", $"Baking {sceneAsset.name}", ((float)sceneIndex / totalScenes));

                    Lightmapping.Bake();

                    EditorSceneManagement.EditorSceneManager.SaveScene(currentScene);

                    EditorSceneManagement.EditorSceneManager.SetActiveScene(trScene);

                    EditorSceneManagement.EditorSceneManager.CloseScene(currentScene, true);
                }

                sceneIndex++;
            }

            EditorUtility.ClearProgressBar();
            EditorBuildSettings.scenes = scenes;

            if (!IsBuildingForEditorPlaymode)
            {
                new CreateSceneListFileFromBuildSettings().Setup();
            }
        }
        public void Setup(string rootImageTemplatePath)
        {
            ColorSpace      colorSpace;
            BuildTarget     buildPlatform;
            RuntimePlatform runtimePlatform;

            GraphicsDeviceType[] graphicsDevices;

            UnityEditor.EditorPrefs.SetBool("AsynchronousShaderCompilation", false);

            // Figure out if we're preparing to run in Editor playmode, or if we're building to run outside the Editor
            if (IsBuildingForEditorPlaymode)
            {
                colorSpace      = QualitySettings.activeColorSpace;
                buildPlatform   = BuildTarget.NoTarget;
                runtimePlatform = Application.platform;
                graphicsDevices = new[] { SystemInfo.graphicsDeviceType };
            }
            else
            {
                buildPlatform   = EditorUserBuildSettings.activeBuildTarget;
                runtimePlatform = Utils.BuildTargetToRuntimePlatform(buildPlatform);
                colorSpace      = PlayerSettings.colorSpace;
                graphicsDevices = PlayerSettings.GetGraphicsAPIs(buildPlatform);
            }

            var bundleBuilds = new List <AssetBundleBuild>();

            foreach (var api in graphicsDevices)
            {
                var images = EditorGraphicsTestCaseProvider.CollectReferenceImagePathsFor(rootImageTemplatePath, colorSpace, runtimePlatform, api);

                Utils.SetupReferenceImageImportSettings(images.Values);

                if (buildPlatform == BuildTarget.NoTarget)
                {
                    continue;
                }

                bundleBuilds.Add(new AssetBundleBuild
                {
                    assetBundleName  = string.Format("referenceimages-{0}-{1}-{2}", colorSpace, runtimePlatform, api),
                    addressableNames = images.Keys.ToArray(),
                    assetNames       = images.Values.ToArray()
                });
            }

            if (bundleBuilds.Count > 0)
            {
                if (!Directory.Exists("Assets/StreamingAssets"))
                {
                    Directory.CreateDirectory("Assets/StreamingAssets");
                }

                foreach (var bundle in bundleBuilds)
                {
                    BuildPipeline.BuildAssetBundles("Assets/StreamingAssets", new [] { bundle }, BuildAssetBundleOptions.None,
                                                    buildPlatform);
                }
            }


            // For each scene in the build settings, force build of the lightmaps if it has "DoLightmap" label.
            // Note that in the PreBuildSetup stage, TestRunner has already created a new scene with its testing monobehaviours

            Scene trScene = EditorSceneManagement.EditorSceneManager.GetSceneAt(0);

            string[] selectedScenes = GetSelectedScenes();

            var sceneIndex  = 0;
            var totalScenes = EditorBuildSettings.scenes.Length;

            foreach (EditorBuildSettingsScene scene in EditorBuildSettings.scenes)
            {
                if (!scene.enabled)
                {
                    continue;
                }

                SceneAsset sceneAsset = AssetDatabase.LoadAssetAtPath <SceneAsset>(scene.path);
                var        labels     = new System.Collections.Generic.List <string>(AssetDatabase.GetLabels(sceneAsset));

                // if we successfully retrieved the names of the selected scenes, we filter using this list
                if (selectedScenes.Length > 0 && !selectedScenes.Contains(sceneAsset.name))
                {
                    continue;
                }

                if (labels.Contains(bakeLabel))
                {
                    EditorSceneManagement.EditorSceneManager.OpenScene(scene.path, EditorSceneManagement.OpenSceneMode.Additive);

                    Scene currentScene = EditorSceneManagement.EditorSceneManager.GetSceneAt(1);

                    EditorSceneManagement.EditorSceneManager.SetActiveScene(currentScene);
#pragma warning disable 618
                    Lightmapping.giWorkflowMode = Lightmapping.GIWorkflowMode.OnDemand;
#pragma warning restore 618
                    EditorUtility.DisplayProgressBar($"Baking Test Scenes {(sceneIndex + 1).ToString()}/{totalScenes.ToString()}", $"Baking {sceneAsset.name}", ((float)sceneIndex / totalScenes));

                    Lightmapping.Bake();

                    EditorSceneManagement.EditorSceneManager.SaveScene(currentScene);

                    EditorSceneManagement.EditorSceneManager.SetActiveScene(trScene);

                    EditorSceneManagement.EditorSceneManager.CloseScene(currentScene, true);
                }

                sceneIndex++;
            }

            EditorUtility.ClearProgressBar();

            if (!IsBuildingForEditorPlaymode)
            {
                new CreateSceneListFileFromBuildSettings().Setup();
            }
        }