Ejemplo n.º 1
0
        public static void ExportScene(List <GameObject> roots, string exportPath = "")
        {
            string sceneName = PathHelper.CurSceneName;

            //导出场景
            try
            {
                ExportImageTools.instance.Clear();
                ResourceManager.instance.Clean();
                //路径
                string scenePath = sceneName + ".scene.json";
                PathHelper.SetSceneOrPrefabPath(scenePath);
                //Scene
                var           scene     = UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene();
                MyJson_Object sceneJson = new MyJson_Object();
                sceneJson.SetUUID(scene.GetHashCode().ToString());//用场景名称的hashCode
                sceneJson.SetUnityID(scene.GetHashCode());
                sceneJson.SetClass("paper.Scene");
                sceneJson.SetString("name", sceneName.Substring(sceneName.LastIndexOf('/') + 1));

                sceneJson.SetColor("ambientColor", RenderSettings.ambientLight);
                sceneJson.SetNumber("lightmapIntensity", UnityEditor.Lightmapping.indirectOutputScale);
                //allGameObjects
                var gameObjectsJson = new MyJson_Array();
                sceneJson["gameObjects"] = gameObjectsJson;
                GameObject[] allObjs = GameObject.FindObjectsOfType <GameObject>();
                for (int i = 0; i < allObjs.Length; i++)
                {
                    gameObjectsJson.AddHashCode(allObjs[i]);
                }
                //lightmaps
                sceneJson["lightmaps"] = ExportSceneTools.AddLightmaps(exportPath);
                ResourceManager.instance.AddObjectJson(sceneJson);
                //序列化
                foreach (var root in roots)
                {
                    SerializeObject.Serialize(root);
                }
                ResourceManager.instance.ExportFiles(scenePath, exportPath);
                MyLog.Log("----场景导出成功----");
            }
            catch (System.Exception e)
            {
                MyLog.LogError(sceneName + "  : 导出失败-----------" + e.StackTrace);
            }
        }
Ejemplo n.º 2
0
        /**
         * 导出场景
         */
        public static void ExportCurScene()
        {
            ExportExtendTools.CleanupMissingScripts();
            //获取场景中的根gameObject
            List <GameObject> roots = new List <GameObject>();

            GameObject[] allObjs = GameObject.FindObjectsOfType <GameObject>();
            for (int i = 0; i < allObjs.Length; i++)
            {
                var tempObj = allObjs[i];
                while (tempObj.transform.parent != null)
                {
                    tempObj = tempObj.transform.parent.gameObject;
                }
                if (!roots.Contains(tempObj))
                {
                    roots.Add(tempObj);
                }
            }
            ExportSceneTools.ExportScene(roots, PathHelper.OutPath);
        }