Esempio n. 1
0
        /**
         * 导出资源
         */
        public static void ExportPrefab(GameObject curObj, string exportPath = "")
        {
            ResourceManager.instance.Clean();
            string prefabPath = "Assets/" + curObj.name + ".prefab.json";

            //如果是Unity预制体那么就导出所在目录,如果是场景的一个普通GameObject,那么导出Assets下
            if (UnityEditor.PrefabUtility.GetPrefabType(curObj) == UnityEditor.PrefabType.PrefabInstance)
            {
                UnityEngine.Object parentObject = UnityEditor.PrefabUtility.GetPrefabParent(curObj);
                prefabPath = UnityEditor.AssetDatabase.GetAssetPath(parentObject) + ".json";
            }
            //保存路径
            PathHelper.SetSceneOrPrefabPath(prefabPath);
            //预制体坐标归零,直接改坐标
            var savePosition = curObj.transform.localPosition;

            if (ExportToolsSetting.instance.prefabResetPos)
            {
                curObj.transform.localPosition = Vector3.zero;
            }

            SerializeObject.Serialize(curObj);
            curObj.transform.localPosition = savePosition;
            ResourceManager.instance.ExportFiles(prefabPath, exportPath);
        }
Esempio n. 2
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);
            }
        }