void SetupLevels(string formatText = null) { // Create a new list int numScenes = UnityEditor.EditorBuildSettings.scenes.Length; List <SceneInfo> newLevels = new List <SceneInfo>(); // Go through each level for (int index = 0; index < numScenes; ++index) { // Grab the scene UnityEditor.EditorBuildSettingsScene scene = UnityEditor.EditorBuildSettings.scenes[index]; // Get the scene name string sceneName = System.IO.Path.GetFileNameWithoutExtension(scene.path); // Make sure the scene doesn't have the same name as the splash, main menu or the credits if ((string.Equals(sceneName, splash.SceneName) == false) && (string.Equals(sceneName, mainMenu.SceneName) == false) && (string.Equals(sceneName, credits.SceneName) == false)) { // Get the display name string displayName = GetDisplayName((newLevels.Count + 1), sceneName, formatText); // Create a new level int ordinal = newLevels.Count; newLevels.Add(new SceneInfo(sceneName, displayName, levelRevertsTimeScaleTemplate, levelLockModeTemplate, ordinal)); } } // Setup the levels array levels = newLevels.ToArray(); }
public static void GenerateSceneList(bool debug) { ProjectSettings projectSettings = GetProjectSettings(); //Get the suite list projectSettings.suiteList.Clear(); // Clear suites list Suite[] foundSuites = Resources.LoadAll <Suite>(""); // Load all Suite scriptable objects into array for (int i = 0; i < foundSuites.Length; i++) { if (debug && foundSuites[i].isDebugSuite || !debug && !foundSuites[i].isDebugSuite) { projectSettings.suiteList.Add(foundSuites[i]); } } UnityEditor.EditorUtility.SetDirty(projectSettings); // Set dirty List <UnityEditor.EditorBuildSettingsScene> buildSettingsScenes = new List <UnityEditor.EditorBuildSettingsScene>(); // Create new build settings scene list AddManualMasterScene(buildSettingsScenes); // Add manual master TODO - Switch this for full automation for (int su = 0; su < projectSettings.suiteList.Count; su++) // Iterate scriptable object list { for (int gr = 0; gr < projectSettings.suiteList[su].groups.Count; gr++) // Iterate groups on the suite { for (int te = 0; te < projectSettings.suiteList[su].groups[gr].tests.Count; te++) // Iterate tests on the group { projectSettings.suiteList[su].groups[gr].tests[te].scenePath = UnityEditor.AssetDatabase.GetAssetPath(projectSettings.suiteList[su].groups[gr].tests[te].scene); UnityEditor.EditorUtility.SetDirty(projectSettings.suiteList[su]); UnityEditor.EditorBuildSettingsScene scene = new UnityEditor.EditorBuildSettingsScene(projectSettings.suiteList[su].groups[gr].tests[te].scenePath, true); // Create new build settings scene from asset path if (!FindDuplicateScene(buildSettingsScenes, projectSettings.suiteList[su].groups[gr].tests[te].scenePath)) // If no duplicate scene found { buildSettingsScenes.Add(scene); // Add to build settings scenes list } } } } UnityEditor.EditorBuildSettings.scenes = buildSettingsScenes.ToArray(); // Set build settings scene list }
public void SetupLevels(string displayNameTemplate, bool fillInSceneName, bool defaultRevertTimeScale, CursorLockMode defaultCursorLockMode, bool appendLevels) { // To prevent conflicts, collect all the scenes we already have listed HashSet <string> usedPaths = new HashSet <string>(); usedPaths.Add(splash.ScenePath); usedPaths.Add(mainMenu.ScenePath); usedPaths.Add(credits.ScenePath); // Create a new list int index = 0; List <SceneInfo> newLevels = new List <SceneInfo>(); // If we're appending, add all the scene info from before if (appendLevels == true) { for (index = 0; index < levels.Length; ++index) { newLevels.Add(levels[index]); usedPaths.Add(levels[index].ScenePath); } } // Go through each level int numScenes = UnityEditor.EditorBuildSettings.scenes.Length; for (index = 0; index < numScenes; ++index) { // Grab the scene UnityEditor.EditorBuildSettingsScene scene = UnityEditor.EditorBuildSettings.scenes[index]; // Make sure the scene doesn't have the same name as the splash, main menu or the credits if ((scene.enabled == true) && (usedPaths.Contains(scene.path) == false)) { // Get the display name int ordinal = newLevels.Count; string displayName = displayNameTemplate; if (fillInSceneName == true) { displayName = string.Format(displayNameTemplate, System.IO.Path.GetFileNameWithoutExtension(scene.path)); } else { displayName = string.Format(displayNameTemplate, (ordinal + 1)); } // Create a new level newLevels.Add(new SceneInfo(scene.path, displayName, defaultRevertTimeScale, defaultCursorLockMode, ordinal)); // Add this path to avoid adding this scene twice usedPaths.Contains(scene.path); } } // Setup the levels array levels = newLevels.ToArray(); }
private static bool IsVaildSceneResource(string fileName) { bool ret = false; if (string.IsNullOrEmpty(fileName)) { return(ret); } string localFileName = GetLocalPath(fileName); if (string.IsNullOrEmpty(localFileName)) { return(ret); } #if UNITY_EDITOR var scenes = UnityEditor.EditorBuildSettings.scenes; if (scenes == null) { return(ret); } var iter = scenes.GetEnumerator(); while (iter.MoveNext()) { UnityEditor.EditorBuildSettingsScene scene = iter.Current as UnityEditor.EditorBuildSettingsScene; if ((scene != null) && scene.enabled) { if (string.Compare(scene.path, localFileName, true) == 0) { ret = true; break; } } } #endif return(ret); }
private IEnumerator _LoadCoroutine(string path, LoaderMode loaderMode, string package, LoadSceneMode loadSceneMode) { string scenePath = ResourceModuleConfig.GameResourcesDir + "/" + path; object getAsset = null; if (ResManager.IsEdiotrMode && Application.isEditor) { #if UNITY_EDITOR var allScenes = UnityEditor.EditorBuildSettings.scenes; UnityEditor.EditorBuildSettingsScene buildScene = null; foreach (var scene in allScenes) { if (scene.path == scenePath) { buildScene = scene; break; } } if (buildScene == null || !buildScene.enabled) { Debug.LogError("EditorMode must add scene to build settings and active:" + path); OnFinish(null); yield break; } ////编辑器状态下模拟异步加载延迟等待指定秒数 //if (loaderMode == LoaderMode.Async) //{ // yield return new WaitForSecondsRealtime(ResManager.EditorModeLoadDelay); //} #else Debug.LogErrorFormat("`IsEditorLoadAsset` is Unity Editor only"); #endif } else { DateTime beginTime = DateTime.Now; string bundlePath = string.IsNullOrEmpty(package) ? path : package; _bundleLoader = AssetBundleLoader.Load(bundlePath + ResourceModuleConfig.AssetBundleExt, null, loaderMode); while (!_bundleLoader.IsCompleted) { if (IsReadyDisposed) // 中途释放 { _bundleLoader.Release(); OnFinish(null); yield break; } this.Progress = _bundleLoader.Progress / 2f; yield return(null); } if (!_bundleLoader.IsSuccess || !_bundleLoader.Bundle.isStreamedSceneAssetBundle) { Debug.LogErrorFormat("[AssetFileLoader]Load BundleLoader Failed(Error) when Finished: {0}", path); _bundleLoader.Release(); OnFinish(null); yield break; } ResManager.LogLoadTime("AssetFileBridge", loaderMode, path, beginTime); } this.Progress = 0.5f; if (loaderMode == LoaderMode.Async) { var asyncOp = SceneManager.LoadSceneAsync(scenePath, loadSceneMode); while (!asyncOp.isDone) { this.Progress = 0.5f + asyncOp.progress / 2f; yield return(null); } } else { SceneManager.LoadScene(scenePath, loadSceneMode); } this.Progress = 1f; getAsset = true; OnFinish(getAsset); //加载完立即释放Loader ReleaseImmediate(); }