Scene and Build Settings related utilities.
static private void UpdateList() { int i; int max = SceneMng.sceneCountInBuildSettings; for (i = 1; i < max; i++) { string name = SceneUtil.GetScenePathByBuildIndex(i); int pos = name.LastIndexOf("/"); char first = name[pos + 1]; /* Every level start with a number, so use this to find the * number of levels */ if (first < '0' && first > '9') { break; } } max = i; _list = new string[max]; for (i = 1; i < max; i++) { _list[i] = ProcessName(SceneUtil.GetScenePathByBuildIndex(i)); } }
void Start() { this.curIdx = 1; this.lastIdx = -1; for (int i = SceneMng.sceneCountInBuildSettings; i > 0; i--) { string name = SceneUtil.GetScenePathByBuildIndex(i - 1); if (name.IndexOf(this.StopLoadingAt) != -1) { this.lastIdx = i - 1; break; } } if (this.lastIdx == -1) { throw new System.Exception("Couldn't find the last level"); } if (CreateLevelSelectors.cache == null) { cache = new CachedLevel[this.lastIdx]; for (int i = 0; i < cache.Length; i++) { CreateLevelSelectors.cache[i].tex = null; CreateLevelSelectors.cache[i].mat = null; } } this.StartCoroutine(this.start()); }
private void listLevels() { this.lastIdx = -1; for (int i = SceneMng.sceneCountInBuildSettings; i > 0; i--) { string name = SceneUtil.GetScenePathByBuildIndex(i - 1); if (name.EndsWith(".unity")) { name = name.Remove(name.Length - 6); } if (name.EndsWith(this.StopLoadingAt)) { this.lastIdx = i - 1; break; } } if (this.lastIdx == -1) { throw new System.Exception("Couldn't find the last level"); } if (LevelSelectMenu.cache == null) { cache = new CachedLevel[this.lastIdx - 1]; for (int i = 0; i < LevelSelectMenu.cache.Length; i++) { LevelSelectMenu.cache[i].tex = null; LevelSelectMenu.cache[i].mat = null; LevelSelectMenu.cache[i].name = LevelNameList.GetLevel(i + 1); } } this.numItems = LevelSelectMenu.cache.Length; }
void OnGUI() { if (projectList == null) { projectList = new ReorderableList(scenesInProject, typeof(SceneInfo), false, false, false, false); projectList.drawHeaderCallback = (Rect rect) => { EditorGUI.LabelField(rect, "Scenes In Project", EditorStyles.boldLabel); }; projectList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { var sceneInfo = scenesInProject[index]; EditorGUI.LabelField(new Rect(rect.x, rect.y, rect.width - 60, rect.height), sceneInfo.name); if (GUI.Button(new Rect(rect.width - 60, rect.y, 20, rect.height), "P", GUIStyle.none)) { EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath <SceneAsset>(sceneInfo.path)); } if (GUI.Button(new Rect(rect.width - 40, rect.y, 20, rect.height), "O", GUIStyle.none)) { List <SceneInfo> scenes = this.GetScenesInHierarchy(); //得到 Hierarchy 中的 已加载的 场景 int sceneIndex = scenes.FindIndex(v => v.path == sceneInfo.path); //确认当前请求添加的场景 的状态 if (sceneIndex == -1) { bool savemodified = EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo(); if (savemodified) //After the user responds positively (with or without saving), open the scene he specified. { int switchIndex = EditorUtility.DisplayDialogComplex("OpenSceneMode", "Addition:Add scene and keep the loaded scene\nSingle:Will Remove all the loaded scene of hierarchy", "Single", "Cancel", "Addition"); switch (switchIndex) { case 0: EditorSceneManager.OpenScene(sceneInfo.path); break; case 2: EditorSceneManager.OpenScene(sceneInfo.path, OpenSceneMode.Additive); break; case 1: default: this.ShowNotification(new GUIContent("Aborting!")); break; } } else { this.ShowNotification(new GUIContent("Aborting!")); } } else //If it is stay in the hierarchy,no matter whether it is load or unload, ping this scene { EditorGUIUtility.PingObject(scenes[sceneIndex].instanceID); this.ShowNotification(new GUIContent("This scene already in the hierarchy!")); } } if (GUI.Button(new Rect(rect.width - 20, rect.y, 20, rect.height), "A", GUIStyle.none)) { int sceneIndex = SceneUtility.GetBuildIndexByScenePath(sceneInfo.path); if (sceneIndex == -1) { var tmpSceneIn = EditorBuildSettings.scenes.ToList(); tmpSceneIn.Add(new EditorBuildSettingsScene(sceneInfo.path, true)); EditorBuildSettings.scenes = tmpSceneIn.ToArray(); ADB.Refresh(); } else { this.ShowNotification(new GUIContent("This scene already in the buildlist!")); } } }; } if (settingList == null) { settingList = new ReorderableList(scenesInSettings, typeof(SceneInfo), true, false, false, true); settingList.onReorderCallback = (ReorderableList list) => { EditorBuildSettings.scenes = list.list.Cast <SceneInfo>() .Select(scene => { var editorScene = new EditorBuildSettingsScene(); editorScene.enabled = scene.enabledInSettings; editorScene.path = scene.path; return(editorScene); }) .ToArray(); }; settingList.drawHeaderCallback = (Rect rect) => { EditorGUI.LabelField(rect, "Scenes In Setting", EditorStyles.boldLabel); }; settingList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { var sceneInfo = scenesInSettings[index]; sceneInfo.enabledInSettings = GUI.Toggle(new Rect(rect.x, rect.y, 14, rect.height), sceneInfo.enabledInSettings, string.Empty); var tmpScenesInSetting = EditorBuildSettings.scenes.ToList(); tmpScenesInSetting.Where(scene => scene.path == sceneInfo.path).First().enabled = sceneInfo.enabledInSettings; EditorGUI.LabelField(new Rect(rect.x + 14, rect.y, rect.width - 34, rect.height), sceneInfo.name); EditorGUI.LabelField(new Rect(rect.width - 8, rect.y, 20, rect.height), index.ToString()); if (GUI.Button(new Rect(rect.width - 65, rect.y, 20, rect.height), "PH", GUIStyle.none)) { int id = this.GetInstanceId(sceneInfo); if (id != -1) { RemoveNotification(); EditorGUIUtility.PingObject(id); } else { ShowNotification(new GUIContent("The scene you pinged is not in hierarchy!")); } } if (GUI.Button(new Rect(rect.width - 30, rect.y, 20, rect.height), "PP", GUIStyle.none)) { var assetObj = ADB.LoadAssetAtPath <SceneAsset>(sceneInfo.path); if (null != assetObj) { RemoveNotification(); EditorGUIUtility.PingObject(assetObj); } } }; settingList.onRemoveCallback = (ReorderableList list) => { if (EditorUtility.DisplayDialog("Attention:", "Really want to remove this scene from the BuildList?", "Yes", "No")) { var tempList = EditorBuildSettings.scenes.ToList(); tempList.RemoveAt(list.index); tempList.TrimExcess(); EditorBuildSettings.scenes = tempList.ToArray(); ReorderableList.defaultBehaviours.DoRemoveButton(list); } }; } scenesInProject = GetScenesInProject(); scenesInSettings = GetScenesInSettings(); projectList.list = scenesInProject; settingList.list = scenesInSettings; // settingScrollPosition = EditorGUILayout.BeginScrollView(settingScrollPosition); settingList.DoLayoutList(); //EditorGUILayout.EndScrollView(); projectScrollPosition = EditorGUILayout.BeginScrollView(projectScrollPosition); projectList.DoLayoutList(); EditorGUILayout.EndScrollView(); }