public void OnGUI() { Refresh(); Scene activeScene = EditorSceneManager.GetActiveScene(); foreach (string path in _scenePaths) { Scene scene = SceneManager.GetSceneByPath(path); bool isActiveScene = activeScene == scene; EditorGUI.BeginDisabledGroup(isActiveScene); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(CoreEditorUtils.GetSceneNameFromPath(path)); if (GUILayout.Button("Import")) { ImportScene(path); } if (GUILayout.Button("Open")) { OpenScene(path); } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); } }
private void ImportScene(string path) { EditorSceneManager.OpenScene(path, UnityEditor.SceneManagement.OpenSceneMode.Additive); Scene scene = SceneManager.GetSceneByPath(path); Scene activeScene = EditorSceneManager.GetActiveScene(); EditorSceneManager.MergeScenes(scene, activeScene); }
private void ImportScene(string path) { WindowView windowController = GameObject.FindObjectOfType <WindowView>(); if (windowController == null) { Debug.LogError("WindowController not found in scene."); return; } Scene scene = EditorSceneManager.OpenScene(path, UnityEditor.SceneManagement.OpenSceneMode.Additive); Scene activeScene = EditorSceneManager.GetActiveScene(); ScreenView screenController = null; //EditorSceneManager.MergeScenes(scene, activeScene); GameObject[] rootObjects = scene.GetRootGameObjects(); foreach (GameObject rootObject in rootObjects) { screenController = rootObject.GetComponent <ScreenView>(); if (screenController != null) { break; } } if (screenController == null) { Debug.LogError("ScreenController not found in loaded scene. "); SceneManager.UnloadSceneAsync(scene); return; } else { if (_loadedScreenCache == null) { GameObject cache = new GameObject("Cache"); _loadedScreenCache = cache.AddComponent <LoadedScreenCache>(); } _loadedScreen = new LoadedScreen(scene, screenController, _loadedScreenCache); GameObject duplicateScreen = _loadedScreen.GetDuplicateScreen(); duplicateScreen.transform.SetParent(windowController.transform, false); RectTransform rectTransform = duplicateScreen.GetComponent <RectTransform>(); if (rectTransform) { rectTransform.anchorMin = Vector2.zero; rectTransform.anchorMax = Vector2.one; rectTransform.offsetMax = Vector2.zero; rectTransform.offsetMin = Vector2.zero; rectTransform.hasChanged = false; } _loadedScreenCache.scenePath = scene.path; _loadedScreenCache._duplicateScreen = duplicateScreen; screenController.gameObject.SetActive(false); } }