void MergeScenes(string myPath, string theirPath) { #if UNITY_5_3 || UNITY_5_3_OR_NEWER var newScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene); var myScene = EditorSceneManager.OpenScene(myPath, OpenSceneMode.Additive); #else #if UNITY_5 EditorApplication.NewEmptyScene(); #else EditorApplication.NewScene(); var _allObjects = (GameObject[])Resources.FindObjectsOfTypeAll(typeof(GameObject)); foreach (var obj in _allObjects) { if (obj.transform.parent == null && PrefabUtility.GetPrefabType(obj) != PrefabType.Prefab && PrefabUtility.GetPrefabType(obj) != PrefabType.ModelPrefab && obj.hideFlags == 0) //Want a better way to filter out "internal" objects { DestroyImmediate(obj); } } #endif EditorApplication.OpenSceneAdditive(myPath); #endif var split = myPath.Split('/'); myContainerName = split[split.Length - 1].Replace(".unity", ""); this.myContainer = new GameObject { name = myContainerName }; var myContainer = this.myContainer; Undo.RegisterCreatedObjectUndo(myContainer, "UniMerge"); var myTransform = myContainer.transform; var allObjects = (GameObject[])Resources.FindObjectsOfTypeAll(typeof(GameObject)); foreach (var obj in allObjects) { if (obj.transform.parent == null && PrefabUtility.GetPrefabType(obj) != PrefabType.Prefab && PrefabUtility.GetPrefabType(obj) != PrefabType.ModelPrefab && obj.hideFlags == 0) //Want a better way to filter out "internal" objects { obj.transform.parent = myTransform; } } #if UNITY_5_3 || UNITY_5_3_OR_NEWER SceneManager.MergeScenes(myScene, newScene); #endif #if UNITY_5_3 || UNITY_5_3_OR_NEWER var theirScene = EditorSceneManager.OpenScene(theirPath, OpenSceneMode.Additive); SceneManager.MergeScenes(theirScene, newScene); #else EditorSceneManager.OpenSceneAdditive(theirPath); #endif split = theirPath.Split('/'); theirContainerName = split[split.Length - 1].Replace(".unity", ""); this.theirContainer = new GameObject { name = theirContainerName }; var theirContainer = this.theirContainer; Undo.RegisterCreatedObjectUndo(theirContainer, "UniMerge"); allObjects = (GameObject[])Resources.FindObjectsOfTypeAll(typeof(GameObject)); foreach (var obj in allObjects) { if (obj.transform.parent == null && obj.name != myContainerName && PrefabUtility.GetPrefabType(obj) != PrefabType.Prefab && PrefabUtility.GetPrefabType(obj) != PrefabType.ModelPrefab && obj.hideFlags == 0) //Want a better way to filter out "internal" objects { obj.transform.parent = theirContainer.transform; } } }
public override void Perform(DiagramViewModel node) { if (!EditorApplication.SaveCurrentSceneIfUserWantsTo()) { return; } if (!EditorUtility.DisplayDialog("Warning!", "Before scaffolding the core, make sure you saved and compiled!", "Yes, I saved and compiled!", "Cancel")) { return; } var paths = node.GraphData.Project.SystemDirectory; var scenesPath = System.IO.Path.Combine(paths, "Scenes"); var sceneName = node.GraphData.Project.Name + "KernelScene.unity"; var sceneNameWithPath = System.IO.Path.Combine(scenesPath, sceneName); var prefabName = node.GraphData.Project.Name + "Kernel.prefab"; var project = node.GraphData.Project as Object; var path = AssetDatabase.GetAssetPath(project); var prefabNameWithPath = path.Replace(project.name + ".asset", prefabName); var relativeScenesPath = System.IO.Path.Combine(node.GraphData.AssetDirectory, "Scenes"); var relativeScenePath = System.IO.Path.Combine(relativeScenesPath, sceneName); uFrameKernel uFrameMVVMKernel = null; if (File.Exists(sceneNameWithPath)) { //EditorApplication.OpenScene(sceneNameWithPath); var gameObject = (GameObject)AssetDatabase.LoadAssetAtPath(prefabNameWithPath, typeof(GameObject)); uFrameMVVMKernel = gameObject.GetComponent <uFrameKernel>(); SyncKernel(node, uFrameMVVMKernel.gameObject); } else { #if UNITY_5 EditorApplication.NewEmptyScene(); #else EditorApplication.NewScene(); #endif if (!Directory.Exists(scenesPath)) { Directory.CreateDirectory(scenesPath); } uFrameMVVMKernel = FindComponentInScene <uFrameKernel>() ?? new GameObject("Kernel").AddComponent <uFrameKernel>(); var services = SyncKernel(node, uFrameMVVMKernel.gameObject); services.gameObject.AddComponent <ViewService>(); services.gameObject.AddComponent <SceneManagementService>(); // var pref ab : Object = PrefabUtility.CreateEmptyPrefab(localPath); //PrefabUtility.ReplacePrefab(obj, prefab, ReplacePrefabOptions.ConnectToPrefab); PrefabUtility.CreatePrefab(prefabNameWithPath, uFrameMVVMKernel.gameObject, ReplacePrefabOptions.ConnectToPrefab); EditorApplication.SaveScene(relativeScenePath); } if (!UnityEditor.EditorBuildSettings.scenes.Any(s => { return(s.path.EndsWith(node.GraphData.Project.Name + "KernelScene.unity")); })) { var list = EditorBuildSettings.scenes.ToList(); list.Add(new EditorBuildSettingsScene(relativeScenePath, true)); EditorBuildSettings.scenes = list.ToArray(); } AssetDatabase.Refresh(); }
public FlowSceneItem(FlowSystemEditorWindow rootWindow, FlowWindow window, AnimatedValues.AnimFloat progressValue) { this.isLocked = false; this.rootWindow = rootWindow; this.window = window; this.currentScene = EditorApplication.currentScene; this.layouts = new List <WindowLayout>(); this.layoutPrefab = null; this.screens = new List <WindowBase>(); this.screenPrefab = null; #if UNITY_5_0 EditorApplication.NewEmptyScene(); #else EditorApplication.NewScene(); #endif var popupOffset = 100f; var popupSize = new Vector2(rootWindow.position.width - popupOffset * 2f, rootWindow.position.height - popupOffset * 2f); var popupRect = new Rect(rootWindow.position.x + popupOffset, rootWindow.position.y + popupOffset, popupSize.x, popupSize.y); this.view = FlowSceneViewWindow.CreateInstance <FlowSceneViewWindow>(); FlowSceneView.recompileChecker = this.view; this.view.title = "UI.Windows Flow Screen Editor ('" + this.window.title + "')"; this.view.position = popupRect; this.view.rootWindow = rootWindow; /*this.inspector = FlowInspectorWindow.CreateInstance<FlowInspectorWindow>(); * this.inspector.position = popupRect; * this.inspector.rootWindow = rootWindow; * this.inspector.Repaint(); * this.inspector.Focus(); * * this.hierarchy = FlowHierarchyWindow.CreateInstance<FlowHierarchyWindow>(); * this.hierarchy.position = popupRect; * this.hierarchy.rootWindow = rootWindow; * this.hierarchy.Repaint(); * this.hierarchy.Focus();*/ this.Show(); //this.inspector.Repaint(); //this.inspector.Focus(); //this.hierarchy.Repaint(); //this.hierarchy.Focus(); this.view.Repaint(); this.view.Focus(); this.autoloadedScreen = false; this.ReloadScreens(); this.autoloadedLayout = false; this.ReloadLayouts(); this.defaultRects = false; progressValue.valueChanged.AddListener(() => { this.view.DrawProgress(progressValue.value); //this.inspector.DrawProgress(progressValue.value); //this.hierarchy.DrawProgress(progressValue.value); if (progressValue.value == progressValue.target) { this.view.Repaint(); this.view.Focus(); } }); }