using System; using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEngine.SceneManagement; namespace MoreMountains.Tools { /// /// Scene management helpers /// public class MMScene { /// /// Returns an array filled with all the currently loaded scenes /// /// public static Scene[] GetLoadedScenes() { int sceneCount = SceneManager.sceneCount; List loadedScenes = new List(sceneCount); // Scene[] loadedScenes = new Scene[sceneCount]; for (int i = 0; i < sceneCount; i++) { var scene = SceneManager.GetSceneAt(i); if (scene.isLoaded) { loadedScenes.Add(scene); } else { Debug.LogWarning($"{scene.name} NOT LOADED"); } } return loadedScenes.ToArray(); } /// /// Returns a list of all the scenes present in the build /// /// public static List GetScenesInBuild() { List scenesInBuild = new List(); for (int i = 0; i < SceneManager.sceneCountInBuildSettings; i++) { string scenePath = SceneUtility.GetScenePathByBuildIndex(i); int lastSlash = scenePath.LastIndexOf("/", StringComparison.Ordinal); scenesInBuild.Add(scenePath.Substring(lastSlash + 1, scenePath.LastIndexOf(".", StringComparison.Ordinal) - lastSlash - 1)); } return scenesInBuild; } /// /// Returns true if a scene by the specified name is present in the build /// /// /// public static bool SceneInBuild(string sceneName) { return GetScenesInBuild().Contains(sceneName); } } }