private static void OpenScene(string path) { int option = EditorUtility.DisplayDialogComplex("Select Scene Loading Mode", "Select Single mode if you want to close all previous scenes and Additive if you want to add selected scene to current opened scene.", "Single", "Additive", "Cancel"); switch (option) { case 0: Scene[] scenes = new Scene[SceneManager.sceneCount]; for (int i = 0; i < scenes.Length; i++) { scenes[i] = SceneManager.GetSceneAt(i); } EditorSceneManager.SaveModifiedScenesIfUserWantsTo(scenes); EditorSceneManager.OpenScene(path, OpenSceneMode.Single); break; case 1: EditorSceneManager.OpenScene(path, OpenSceneMode.Additive); break; } }
public static bool PromptUserToSaveDirtyScenes(AssetList assetList) { List <Scene> scenes = new List <Scene>(); for (int i = 0; i < SceneManager.sceneCount; i++) { Scene scene = SceneManager.GetSceneAt(i); Asset asset = Provider.GetAssetByPath(scene.path); if (asset != null && asset.IsUnderVersionControl && scene.isDirty) { scenes.Add(scene); } } if (scenes.Count > 0) { List <Scene> filteredScenes = new List <Scene>(); foreach (var asset in assetList) { foreach (var scene in scenes) { if (asset.path.Equals(scene.path)) { filteredScenes.Add(scene); break; } } } if (filteredScenes.Count > 0) { if (!EditorSceneManager.SaveModifiedScenesIfUserWantsTo(filteredScenes.ToArray())) { return(false); } } } return(true); }
public void OpenMasterScene() { List <Scene> loadedScenes = new List <Scene>(); for (int i = 0; i < SceneManager.sceneCount; i++) { loadedScenes.Add(SceneManager.GetSceneAt(i)); } Scene[] loadedScenesArray = loadedScenes.ToArray(); EditorSceneManager.SaveModifiedScenesIfUserWantsTo(loadedScenesArray); string scenePath = "Assets/" + GameLevelToolkitWindow.GetProjectPathStringWithSlash() + "Scenes/" + SceneAndResourceFolderName.folderNameValue + "/Master Scene/Master Scene.unity"; if (openAdditively == true) { EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Additive); } else { EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Single); } }
public static void OpenScene(string scenePath) { if (EditorApplication.isPlayingOrWillChangePlaymode) { return; } List <Scene> scenesToSave = new List <Scene>(); for (int i = 0; i < EditorSceneManager.sceneCount; i++) { Scene sceneAt = EditorSceneManager.GetSceneAt(i); if (sceneAt.isDirty) { scenesToSave.Add(sceneAt); } } if (EditorSceneManager.SaveModifiedScenesIfUserWantsTo(scenesToSave.ToArray())) { EditorSceneManager.OpenScene(scenePath); } }
private void Init() { button = new iButton(); button.OnClicked = (sender) => { if (EditorSceneManager.SaveModifiedScenesIfUserWantsTo(new Scene[] { SceneManager.GetActiveScene() })) { EditorSceneManager.OpenScene(path); if (iSceneNavigation.window != null) { iSceneNavigation.window.Close(); } } }; icon = new iBox(); icon.size = new Vector2(16, 16); icon.style = new GUIStyle(); icon.LoadBuiltInIcon("SceneAsset Icon"); label = new iLabel(); }
public static bool OnOpenAsset(int instanceID, int line) { SceneInfo sceneInfo = EditorUtility.InstanceIDToObject(instanceID) as SceneInfo; if (sceneInfo != null) { if (sceneInfo.Editor_GetScene() != null) { Scene[] allScenes = new Scene[SceneManager.sceneCount]; for (int i = 0; i < SceneManager.sceneCount; i++) { allScenes[i] = SceneManager.GetSceneAt(i); } if (EditorSceneManager.SaveModifiedScenesIfUserWantsTo(allScenes)) { EditorSceneManager.OpenScene(AssetDatabase.GetAssetOrScenePath(sceneInfo.Editor_GetScene())); } return(true); } } return(false); // we did not handle the open }
public static void Draw(Rect position, SceneReference scene, GUIContent label, AssetLocation location, string newSceneName, Action creator) { var rect = EditorGUI.PrefixLabel(position, label); var refreshRect = RectHelper.TakeTrailingIcon(ref rect); if (GUI.Button(refreshRect, _refreshScenesButton.Content, GUIStyle.none)) { SceneHelper.RefreshLists(); } var list = SceneHelper.GetSceneList(true, location != AssetLocation.None); var index = list.GetIndex(scene.Path); if (index != 0 && scene.IsAssigned) { var loadRect = RectHelper.TakeTrailingIcon(ref rect); var s = scene.Scene; using (ColorScope.ContentColor(Color.black)) { if (s.IsValid() && s.isLoaded) { if (GUI.Button(loadRect, _unloadSceneButton.Content, GUIStyle.none)) { if (EditorSceneManager.SaveModifiedScenesIfUserWantsTo(new Scene[] { s })) { EditorSceneManager.CloseScene(s, true); } } } else { if (GUI.Button(loadRect, _loadSceneButton.Content, GUIStyle.none)) { s = EditorSceneManager.OpenScene(scene.Path, OpenSceneMode.Additive); SceneManager.SetActiveScene(s); } } } } var thumbnail = AssetPreview.GetMiniTypeThumbnail(typeof(SceneAsset)); var start = scene.Path.LastIndexOf('/') + 1; var popupLabel = index != 0 && scene.IsAssigned ? new GUIContent(scene.Path.Substring(start, scene.Path.Length - start - 6), thumbnail) : new GUIContent("None"); var selection = SelectionPopup.Draw(rect, popupLabel, new SelectionState { Tab = 0, Index = index }, list.Tree); if (selection.Tab == 0 && selection.Index != index) { scene.Path = list.GetPath(selection.Index); } else if (selection.Tab == 1) { var newScene = SceneHelper.CreateScene(location, newSceneName, creator); scene.Path = newScene.path; } if (DragAndDrop.objectReferences.Length > 0 && rect.Contains(Event.current.mousePosition)) { var obj = DragAndDrop.objectReferences[0]; if (obj is SceneAsset asset) { if (Event.current.type == EventType.DragUpdated) { DragAndDrop.visualMode = DragAndDropVisualMode.Link; Event.current.Use(); } if (Event.current.type == EventType.DragPerform) { scene.Path = AssetDatabase.GetAssetPath(asset); DragAndDrop.AcceptDrag(); } } } }
public static void OpenLevel(GameLevel targetGameLevel, bool includeMasterScene, bool keepCurrentScenesThatAreOpenOpeneded, bool includeDependencies) { List <Scene> loadedScenes = new List <Scene>(); for (int i = 0; i < SceneManager.sceneCount; i++) { loadedScenes.Add(SceneManager.GetSceneAt(i)); } Scene[] loadedScenesArray = loadedScenes.ToArray(); EditorSceneManager.SaveModifiedScenesIfUserWantsTo(loadedScenesArray); //Load The Master Scene if (includeMasterScene == true) { string masterScenePath = "Assets/" + GameLevelToolkitWindow.GetProjectPathStringWithSlash() + "Scenes/" + SceneAndResourceFolderName.folderNameValue + "/Master Scene/Master Scene.unity"; Scene masterScene; if (keepCurrentScenesThatAreOpenOpeneded == true) { masterScene = EditorSceneManager.OpenScene(masterScenePath, OpenSceneMode.Additive); } else { masterScene = EditorSceneManager.OpenScene(masterScenePath, OpenSceneMode.Single); } EditorSceneManager.SetActiveScene(masterScene); } //Unload Any Existing Scenes If Required if (includeMasterScene == false && keepCurrentScenesThatAreOpenOpeneded == false) { for (int i = 0; i < SceneManager.sceneCount; i++) { Scene scene = SceneManager.GetSceneAt(i); if (!IsActiveScene(scene)) { CloseScene(scene); } if (scene.name == "Master Scene") { if (!IsActiveScene(scene)) { EditorSceneManager.SetActiveScene(scene); } } } } //Load The Locations Scenes LoadLocationsScenesAdditively(targetGameLevel); //Load Dependencies If Required if (includeDependencies == true) { for (int i = 0; i < targetGameLevel.levelDependencies.Count; i++) { LoadLocationsScenesAdditively(targetGameLevel.levelDependencies[i]); } } }
/// <summary> /// Load a new scene group and unload the current one by group reference, editor only /// </summary> /// <param name="groupName">The target group</param> public static void OpenSceneBundle(SceneBundle newBundle) { //This value will be incremented each persisant scene loaded, will be checked later to get missing persistant scenes var persistantScenesCheckCount = 0; //Register dirty scenes var dirtyScenes = new List <Scene>(); var saveFlag = false; SceneAsset[] persistantScenesAssets = SceneBundleEditor.GetBundleScenesAssets(CurrentSceneList.PersistantScenesBundle); bool hasPersistantBundle = persistantScenesAssets != null; for (int i = 0; i < EditorSceneManager.sceneCount; i++) { //Filter persistant scenes Scene scene = EditorSceneManager.GetSceneAt(i); //Check if opended scenes are dirty to call a save pannel if (scene.isDirty && !saveFlag) { saveFlag = true; } //Check if iterated scene is persisant var persisantFlag = false; if (hasPersistantBundle) { for (int j = 0; j < persistantScenesAssets.Length; j++) { if (scene.name == persistantScenesAssets[j].name) { persisantFlag = true; } } } if (!persisantFlag) { dirtyScenes.Add(scene); } else { //Doesn't add persistant scenes to dirty list persistantScenesCheckCount++; //Count persistant scenes to check if each one is correctly loaded } } //Asks the user to save the scenes if a dirty one is detected if (saveFlag) { EditorSceneManager.SaveModifiedScenesIfUserWantsTo(dirtyScenes.ToArray()); } //Check if all the scenes will be unload var fullLoad = EditorSceneManager.sceneCount <= dirtyScenes.Count; //Unload current scene except persistant ones, skip one scene if all scenes have to be reloaded for (int i = fullLoad ? 1 : 0; i < dirtyScenes.Count; i++) { EditorSceneManager.CloseScene(dirtyScenes[i], true); } //Load scenes in the bundle SceneAsset[] newBundleSceneAssets = SceneBundleEditor.GetBundleScenesAssets(newBundle); var scenesPaths = new string[newBundleSceneAssets.Length]; for (int i = 0; i < newBundleSceneAssets.Length; i++) { scenesPaths[i] = AssetDatabase.GetAssetPath(newBundleSceneAssets[i]); } //Threat first scene var firstSceneLoadMode = fullLoad ? OpenSceneMode.Single : OpenSceneMode.Additive; Scene active = EditorSceneManager.OpenScene(scenesPaths[0], firstSceneLoadMode); for (int i = 1; i < scenesPaths.Length; i++) { EditorSceneManager.OpenScene(scenesPaths[i], OpenSceneMode.Additive); } //Check if persistant scenes are correctly loaded if (hasPersistantBundle && persistantScenesCheckCount != persistantScenesAssets.Length) { //Re-open persistant scenes for (int i = 0; i < persistantScenesAssets.Length; i++) { var scenePath = AssetDatabase.GetAssetPath(persistantScenesAssets[i]); Scene scene = EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Additive); EditorSceneManager.MoveSceneBefore(scene, EditorSceneManager.GetSceneAt(i)); } } //Active the first loaded scene of the bundle EditorSceneManager.SetActiveScene(active); }