Пример #1
0
 private static bool TestExportCurrentScene()
 {
     ResExportUtil.ExportCurrentScene(true, false);
     return(true);
 }
Пример #2
0
        /// <summary>
        /// 生成场景
        /// </summary>
        void BuildScene(bool exportScene, bool exportRes, bool compressScene, bool compressRes)
        {
            // 先保存场景
            EditorApplication.SaveScene();

            // 场景名字
            var    scenePath = EditorApplication.currentScene;
            string sceneName = UtilityTools.GetFileName(scenePath);

            // 导出目录
            var exportPath = UtilityTools.GenResExportPath(string.Format("scene/{0}", sceneName), sceneName);
            var exportDir  = Path.GetDirectoryName(exportPath);

            // 删除目录
            if (exportRes && exportScene)
            {
                Directory.Delete(exportDir, true);
            }

            // 创建目录
            if (!Directory.Exists(exportDir))
            {
                Directory.CreateDirectory(exportDir);
            }

            /// 开始处理数据
            try
            {
                do
                {
                    AssetsBackuper.inst.Clear();
                    if (exportScene)
                    {
                        var outputDir = EditorUtil.GetSceneOutputPath(null);
                        AssetDatabase.DeleteAsset(outputDir);
                        var outputPath = EditorUtil.GetSceneOutputPath(string.Format("{0}.unity", sceneName));
                        EditorApplication.SaveScene(outputPath);
                    }

                    // 树结构
                    var meshColliders = new List <MeshCollider>();
                    var trees         = SceneTree.Build(_settings.trees, meshColliders);
                    if (null == trees)
                    {
                        break;
                    }
                    SaveSettings();
                    SceneTree.Export(trees, meshColliders, exportRes, compressRes);

                    // 准备导出
                    EditorApplication.SaveScene();
                    AssetDatabase.SaveAssets();

                    if (exportScene)
                    {
                        ResExportUtil.ExportCurrentScene(true, compressScene);
                    }
                }while(false);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                AssetsBackuper.inst.Recover();
                AssetDatabase.SaveAssets();
            }

            finally
            {
                // 还原修改过的资源和场景
                if (_recovertScene)
                {
                    AssetsBackuper.inst.Recover();
                    AssetDatabase.SaveAssets();
                    AssetDatabase.Refresh();
                    EditorApplication.OpenScene(scenePath);
                    Resources.UnloadUnusedAssets();
                }
            }
        }