Esempio n. 1
0
 public static void BakeMultipleScenes(string[] paths)
 {
     if (paths.Length != 0)
     {
         for (int i = 0; i < paths.Length; i++)
         {
             for (int k = i + 1; k < paths.Length; k++)
             {
                 if (paths[i] == paths[k])
                 {
                     throw new Exception("no duplication of scenes is allowed");
                 }
             }
         }
         SetLoadLevelForMultiLevelBake(true);
         string currentScene = EditorApplication.currentScene;
         bool   isSceneDirty = false;
         if (string.IsNullOrEmpty(currentScene))
         {
             isSceneDirty = EditorApplication.isSceneDirty;
             EditorApplication.SaveScene("Temp/MultiLevelBakeTemp.unity", true);
         }
         else
         {
             EditorApplication.SaveScene();
         }
         EditorApplication.OpenScene(paths[0]);
         for (int j = 1; j < paths.Length; j++)
         {
             EditorApplication.OpenSceneAdditive(paths[j]);
         }
         giWorkflowMode = GIWorkflowMode.OnDemand;
         BakeMultipleScenes_Internal(paths);
         foreach (UnityEngine.Object obj2 in AssetDatabase.LoadAllAssetsAtPath(Path.GetDirectoryName(paths[0]) + "/" + Path.GetFileNameWithoutExtension(paths[0]) + "/LightmapSnapshot.asset"))
         {
             LightmapSnapshot snapshot = obj2 as LightmapSnapshot;
             if (snapshot != null)
             {
                 EditorApplication.OpenScene(AssetDatabase.GUIDToAssetPath(snapshot.sceneGUID));
                 giWorkflowMode = GIWorkflowMode.OnDemand;
                 if (lightmapSnapshot != snapshot)
                 {
                     lightmapSnapshot = snapshot;
                     EditorApplication.SaveScene();
                 }
             }
         }
         SetLoadLevelForMultiLevelBake(false);
         if (string.IsNullOrEmpty(currentScene))
         {
             EditorApplication.OpenScene("Temp/MultiLevelBakeTemp.unity");
             EditorApplication.currentScene = string.Empty;
             if (isSceneDirty)
             {
                 EditorApplication.MarkSceneDirty();
             }
         }
         else
         {
             EditorApplication.OpenScene(currentScene);
         }
     }
 }
Esempio n. 2
0
        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;
                }
            }
        }