using System; using UnityEditor.Build.Pipeline.Utilities; using UnityEditor.SceneManagement; using System.Linq; namespace UnityEditor.Build.Utilities { /// /// Cleans up scenes in the scene manager. /// public class SceneStateCleanup : IDisposable { SceneSetup[] m_Scenes; bool m_Disposed; /// /// Creates a new scene state cleanup object. /// public SceneStateCleanup() { m_Scenes = EditorSceneManager.GetSceneManagerSetup(); } /// /// Disposes of the scene state cleanup instance. /// public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } /// /// Disposes of the scene state cleanup instance. /// /// Set to true to reset the scenes list. Set to false to leave the scenes list as is. protected virtual void Dispose(bool disposing) { if (m_Disposed) return; m_Disposed = true; if (disposing) { // Test runner injects scenes, so we strip those here var scenes = m_Scenes.Where(s => !string.IsNullOrEmpty(s.path)).ToArray(); if (!scenes.IsNullOrEmpty()) EditorSceneManager.RestoreSceneManagerSetup(scenes); else EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects); } } } }