コード例 #1
0
        public static void Export(string baseDir, string exportPath)
        {
            {
                var relativePath = ExportSetting.instance.GetExportPath(exportPath);
                var filePath     = PathHelper.CheckFileName(System.IO.Path.Combine(baseDir, relativePath));
                var fileDir      = PathHelper.GetFileDirectory(filePath);
                if (!System.IO.Directory.Exists(fileDir))
                {
                    System.IO.Directory.CreateDirectory(fileDir);
                }
                var gltfFile = File.CreateText(filePath);
                SerializeObject.currentData.Serialize(gltfFile);
                gltfFile.Close();
                MyLog.Log("---导出文件:" + relativePath);
            }

            {
                foreach (var asset in SerializeObject.assetsData.Values)
                {
                    var relativePath = ExportSetting.instance.GetExportPath(asset.uri);
                    var filePath     = PathHelper.CheckFileName(System.IO.Path.Combine(baseDir, relativePath));
                    var fileDir      = PathHelper.GetFileDirectory(filePath);
                    if (!System.IO.Directory.Exists(fileDir))
                    {
                        System.IO.Directory.CreateDirectory(fileDir);
                    }
                    System.IO.File.WriteAllBytes(filePath, asset.buffer);
                }
            }
        }
コード例 #2
0
 public void ExportFiles(string sceneOrPrefabPath, string exportPath = "")
 {
     //得到.prefab.json和.scene.json的数据
     System.Text.StringBuilder sb = new System.Text.StringBuilder();
     this.ConvertJsonToString(sb);
     //
     byte[] bs = System.Text.Encoding.UTF8.GetBytes(sb.ToString());
     this.AddFileBuffer(sceneOrPrefabPath, bs);
     //
     if (!System.IO.Directory.Exists(exportPath))
     {
         System.IO.Directory.CreateDirectory(exportPath);
     }
     foreach (var fileBuffer in ResourceManager.instance.fileBuffers)
     {
         if (string.IsNullOrEmpty(fileBuffer.Key))
         {
             continue;
         }
         //写入文件
         var filePath = PathHelper.CheckFileName(System.IO.Path.Combine(exportPath, fileBuffer.Key));
         MyLog.Log("---导出文件:" + fileBuffer.Key);
         //创建路径
         var fileDirectory = filePath.Substring(0, filePath.LastIndexOf("/") + 1);
         if (!System.IO.Directory.Exists(fileDirectory))
         {
             System.IO.Directory.CreateDirectory(fileDirectory);
         }
         System.IO.File.WriteAllBytes(filePath, fileBuffer.Value);
     }
 }
コード例 #3
0
        public static AssetData SerializeAsset(UnityEngine.Object obj)
        {
            var path = PathHelper.GetAssetPath(obj);

            MyLog.Log("SerializeAsset path:" + path);
            if (assetsData.ContainsKey(path))
            {
                MyLog.Log("has key:" + path);
                return(assetsData[path]);
            }

            var assetData = AssetData.Create(path);

            assetsData.Add(path, assetData);
            var parserType = obj.GetType().Name;

            if (!assetParsers.ContainsKey(parserType))
            {
                MyLog.Log("AssetData SerializeAsset 找不到该类型:" + parserType);
            }
            else
            {
                var parser = assetParsers[obj.GetType().Name];
                parser.Serialize(obj, assetData);
            }
            return(assetData);
        }
コード例 #4
0
        public static void Reload(string configPath, string defaultExportPath)
        {
            if (System.IO.File.Exists(configPath))
            {
                var jsonStr = System.IO.File.ReadAllText(configPath, System.Text.Encoding.UTF8);
                _instance = JsonConvert.DeserializeObject <ExportSetting>(jsonStr);
            }
            else
            {
                _instance = new ExportSetting();
            }

            if (!System.IO.Directory.Exists(_instance.exportDir))
            {
                _instance.exportDir = defaultExportPath;
            }

            if (_instance.shader != null)
            {
                foreach (var customShader in _instance.shader)
                {
                    MyLog.Log("customShader:" + customShader.Key);
                }
            }
        }
コード例 #5
0
        public byte[] EncodeToPNG(Texture2D source, string ext = "png")
        {
            var             path     = AssetDatabase.GetAssetPath(source);
            TextureImporter importer = (TextureImporter)TextureImporter.GetAtPath(path);

            MyLog.Log("---导出图片:" + source.name + " path:" + path);
            var saveTextureType = TextureImporterType.Default;
            var isRestore       = false;

            if (importer)
            {
                saveTextureType = importer.textureType;
                if (saveTextureType == TextureImporterType.NormalMap && !ExportToolsSetting.instance.unityNormalTexture)
                {
                    //法线贴图类型贴图因为Unity特殊处理过,如果要正常导出,就要转换一下类型
                    isRestore            = true;
                    importer.textureType = TextureImporterType.Default;
                    importer.SaveAndReimport();
                }
            }

            var renderTexture = RenderTexture.GetTemporary(source.width, source.height);

            Graphics.Blit(source, renderTexture);
            RenderTexture.active = renderTexture;
            var exportTexture = new Texture2D(source.width, source.height);

            exportTexture.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
            exportTexture.Apply();

            byte[] res = null;
            try
            {
                if (ext == "jpg" || ext == "jpeg")
                {
                    res = exportTexture.EncodeToJPG();
                }
                else if (ext == "exr")
                {
                    res = exportTexture.EncodeToEXR();
                }
                else
                {
                    res = exportTexture.EncodeToPNG();
                }
            }
            catch (System.Exception e)
            {
                MyLog.LogError("图片导出出错:" + path + " 请保证原始资源是可读写,非压缩文件");
            }

            if (isRestore && importer)
            {
                importer.textureType = saveTextureType;
                importer.SaveAndReimport();
            }

            return(res);
        }
コード例 #6
0
        protected override void Update()
        {
            //自定义的value全部导出,不和默认值做过滤
            var target             = this.source;
            var materialProperties = MaterialEditor.GetMaterialProperties(new UnityEngine.Object[] { target });

            foreach (var materialProperty in materialProperties)
            {
                if (materialProperty.flags == MaterialProperty.PropFlags.HideInInspector)
                {
                    continue;
                }

                var    uniform = new MyJson_Tree();
                string type    = materialProperty.type.ToString();
                if (type == "Float" || type == "Range")
                {
                    this.values.SetNumber(materialProperty.name, this.GetFloat(materialProperty.name, 0.0f));
                }
                else if (type == "Vector")
                {
                    this.values.SetVector4(materialProperty.name, this.GetVector4(materialProperty.name, Vector4.zero));
                }
                else if (type == "Color")
                {
                    this.values.SetColor(materialProperty.name, this.GetColor(materialProperty.name, Color.white));
                }
                else if (type == "Texture")
                {
                    var tex = this.GetTexture(materialProperty.name, null);
                    if (tex != null)
                    {
                        string texdim = materialProperty.textureDimension.ToString();
                        if (texdim == "Tex2D")
                        {
                            this.SetTexture(materialProperty.name, tex);

                            string propertyName = materialProperty.name + "_ST";
                            if (target.HasProperty(propertyName))
                            {
                                this.values.SetVector4(propertyName, this.GetVector4(propertyName, Vector4.zero));
                            }
                        }
                        else
                        {
                            throw new Exception("not suport texdim:" + texdim);
                        }
                    }
                }
                else
                {
                    throw new Exception("not support type: " + materialProperty.type);
                }
            }

            MyLog.Log("自定义Shader:" + this.technique);
        }
コード例 #7
0
 public void Clean()
 {
     MyLog.Log("清除缓存");
     this._hashIndex = 1;
     this._hashList.Clear();
     this._objects.Clear();
     this._comps.Clear();
     this._assets.Clear();
     this._fileBuffers.Clear();
     this._saveCache.Clear();
 }
コード例 #8
0
        /**
         * 保存纹理图片
         */
        public string SaveTextureEditor(Texture2D tex, string matPath)
        {
            string localp = System.IO.Path.GetDirectoryName(Application.dataPath);
            string path   = AssetDatabase.GetAssetPath(tex);

            TextureImporter importer = (TextureImporter)TextureImporter.GetAtPath(path);
            bool            isNormal = importer && importer.textureType == TextureImporterType.NormalMap;
            string          filename = localp + "/" + path;
            int             i        = filename.LastIndexOf(".");
            string          ext      = "png";

            if (i >= 0)
            {
                ext = filename.Substring(i + 1);
            }
            byte[] bs;
            string name = tex.name + "." + ext;

            name = PathHelper.CheckFileName(name);
            string rename;

            if (path == "Resources/unity_builtin_extra" || string.IsNullOrEmpty(path))
            {
                path = "Library/" + tex.name + "." + ext;
            }
            {
                var isSupported = true;
                if (ext != "png" && ext != "jpg" && ext != "jpeg")
                {
                    path = path.Substring(0, path.LastIndexOf(".") + 1) + "png";
                    //非png、jpg都导出为png
                    ext         = "png";
                    isSupported = false;
                }

                //只有jpg、png可以原始图片导出,其他类型不支持
                if (ExportToolsSetting.instance.exportOriginalImage && isSupported && System.IO.File.Exists(filename))
                {
                    MyLog.Log("原始图片:" + filename);
                    bs = System.IO.File.ReadAllBytes(filename);
                }
                else
                {
                    bs = ExportImageTools.instance.EncodeToPNG(tex, ext);
                }

                path = PathHelper.CheckFileName(path);
                this.AddFileBuffer(path, bs);
                rename = SaveTextureFormat(tex, path, matPath, false, ext, isNormal);
            }

            return(rename);
        }
コード例 #9
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);
            }
        }
コード例 #10
0
 public bool AddFileBuffer(string key, byte[] buffer)
 {
     if (string.IsNullOrEmpty(key))
     {
         return(false);
     }
     MyLog.Log("添加导出文件:" + key);
     if (this._fileBuffers.ContainsKey(key))
     {
         this._fileBuffers[key] = buffer;
     }
     else
     {
         this._fileBuffers.Add(key, buffer);
     }
     return(true);
 }
コード例 #11
0
        protected override bool Match(Component component)
        {
            var aniamtior = component as Animator;

            if (aniamtior.runtimeAnimatorController == null)
            {
                MyLog.Log("缺少runtimeAnimatorController");
                return(false);
            }
            var clips = aniamtior.runtimeAnimatorController.animationClips;

            if (clips == null || clips.Length == 0)
            {
                MyLog.Log("clips为空");
                return(false);
            }

            return(true);
        }
コード例 #12
0
        private static MyJson_Array AddLightmaps(string exportPath)
        {
            var lightmapsJson = new MyJson_Array();

            foreach (var lightmapData in LightmapSettings.lightmaps)
            {
                Texture2D lmTexture = lightmapData.lightmapColor;
                int       lmID      = lmTexture.GetInstanceID();
                if (!ResourceManager.instance.HaveCache(lmID))
                {
                    //格式转换
                    string suffix       = "png";
                    string relativePath = UnityEditor.AssetDatabase.GetAssetPath(lmTexture);
                    MyLog.Log("导出lightmap:" + relativePath);
                    string exrPath    = Path.Combine(Application.dataPath, relativePath.Replace("Assets/", ""));
                    string ralPngPath = PathHelper.CheckFileName(relativePath.Substring(0, relativePath.LastIndexOf('/') + 1) + lmTexture.name + "." + suffix);
                    string pngPath    = PathHelper.CheckFileName(Path.Combine(exportPath, ralPngPath));
                    // string ralPngPath = relativePath.Substring(0, relativePath.LastIndexOf('/') + 1) + lmTexture.name + "." + suffix;
                    // string pngPath = Path.Combine(exportPath, ralPngPath);

                    exrPath = exrPath.Replace("\\", "/");
                    pngPath = pngPath.Replace("\\", "/");
                    var bs = ExportImageTools.instance.EncodeToPNG(lmTexture);
                    ResourceManager.instance.AddFileBuffer(ralPngPath, bs);
                    // ExportImageTools.instance.AddExr(exrPath, pngPath);
                    //添加到 compList 和 assetsList
                    ResourceManager.instance.SaveTextureFormat(lmTexture, ralPngPath, ralPngPath + ".image", false);
                    string name        = lmTexture.name + ".image.json";
                    var    imgdescPath = PathHelper.CheckFileName(ralPngPath.Substring(0, ralPngPath.LastIndexOf("/") + 1) + name);

                    var assetIndex = ResourceManager.instance.AddAssetUrl(imgdescPath);

                    var assetItem = new MyJson_Tree();
                    assetItem.SetInt("asset", assetIndex);
                    lightmapsJson.Add(assetItem);
                }
            }
            // ExportImageTools.instance.ExrToPng();

            return(lightmapsJson);
        }
コード例 #13
0
        public static Texture2D DeCompress(Texture2D source)
        {
            MyLog.Log("DeCompress: " + source.name);
            RenderTexture renderTex = RenderTexture.GetTemporary(
                source.width,
                source.height,
                0,
                RenderTextureFormat.Default,
                RenderTextureReadWrite.Linear);

            Graphics.Blit(source, renderTex);
            RenderTexture previous = RenderTexture.active;

            RenderTexture.active = renderTex;
            Texture2D readableText = new Texture2D(source.width, source.height);

            readableText.ReadPixels(new Rect(0, 0, renderTex.width, renderTex.height), 0, 0);
            readableText.Apply();
            RenderTexture.active = previous;
            RenderTexture.ReleaseTemporary(renderTex);
            return(readableText);
        }
コード例 #14
0
        public override bool WriteToJson(GameObject gameObject, Component component, MyJson_Object compJson)
        {
            var aniamtior = component as Animator;

            if (aniamtior.runtimeAnimatorController == null)
            {
                MyLog.Log("缺少runtimeAnimatorController");
                return(false);
            }
            var clips = aniamtior.runtimeAnimatorController.animationClips;

            if (clips == null || clips.Length == 0)
            {
                MyLog.Log("clips为空");
                return(false);
            }

            compJson.SetBool("autoPlay", true); // TODO
            compJson.SetAnimation(gameObject, clips);

            return(true);
        }
コード例 #15
0
        protected override void Serialize(Component component, ComponentData compData)
        {
            var            obj  = component.gameObject;
            ParticleSystem comp = component as ParticleSystem;

            //main
            {
                var main     = comp.main;
                var mainItem = new JObject();
                compData.properties.Add(new JProperty("main", mainItem));
                mainItem.SetNumber("duration", main.duration);
                mainItem.SetBool("loop", main.loop);
                this.AddMinMaxCurve(mainItem, "startDelay", main.startDelay);
                this.AddMinMaxCurve(mainItem, "startLifetime", main.startLifetime);
                this.AddMinMaxCurve(mainItem, "startSpeed", main.startSpeed);

                mainItem.SetBool("startSize3D", main.startSize3D);
                if (main.startSize3D)
                {
                    this.AddMinMaxCurve(mainItem, "startSizeX", main.startSizeX);
                    this.AddMinMaxCurve(mainItem, "startSizeY", main.startSizeY);
                    this.AddMinMaxCurve(mainItem, "startSizeZ", main.startSizeZ);
                }
                else
                {
                    this.AddMinMaxCurve(mainItem, "startSizeX", main.startSize);
                    this.AddMinMaxCurve(mainItem, "startSizeY", main.startSize);
                    this.AddMinMaxCurve(mainItem, "startSizeZ", main.startSize);
                }

                mainItem.SetBool("_startRotation3D", main.startRotation3D);
                if (main.startRotation3D)
                {
                    this.AddMinMaxCurve(mainItem, "startRotationX", main.startRotationX);
                    this.AddMinMaxCurve(mainItem, "startRotationY", main.startRotationY);
                    this.AddMinMaxCurve(mainItem, "startRotationZ", main.startRotationZ);
                }
                else
                {
                    this.AddMinMaxCurve(mainItem, "startRotationX", main.startRotation);
                    this.AddMinMaxCurve(mainItem, "startRotationY", main.startRotation);
                    this.AddMinMaxCurve(mainItem, "startRotationZ", main.startRotation);
                }

                this.AddMinMaxGradient(mainItem, "startColor", main.startColor);
                this.AddMinMaxCurve(mainItem, "gravityModifier", main.gravityModifier);
                mainItem.SetEnum("_simulationSpace", main.simulationSpace);
                mainItem.SetEnum("scaleMode", main.scalingMode);
                mainItem.SetBool("playOnAwake", main.playOnAwake);
                var value = this.EstimateMaxParticles(comp);
                mainItem.SetInt("_maxParticles", value);
                MyLog.Log(comp.gameObject.name + " 粒子估算:" + value);
            }

            //emission
            {
                var emissionItem = new JObject();
                compData.properties.Add(new JProperty("emission", emissionItem));
                // compData.properties.Add("emission", emissionItem);
                this.AddMinMaxCurve(emissionItem, "rateOverTime", comp.emission.rateOverTime);
                var burstsArr = new JArray();
                emissionItem.Add("bursts", burstsArr);
                var bursts = new ParticleSystem.Burst[comp.emission.burstCount];
                comp.emission.GetBursts(bursts);
                foreach (var burst in bursts)
                {
                    JArray burstItem = new JArray();
                    burstItem.AddNumber(burst.time);
                    burstItem.AddInt(burst.minCount);
                    burstItem.AddInt(burst.maxCount);
                    burstItem.AddInt(burst.cycleCount);
                    burstItem.AddNumber(burst.repeatInterval);
                    burstsArr.Add(burstItem);
                }
            }
            //shape
            if (comp.shape.enabled)
            {
                var shapItem = new JObject();
                compData.properties.Add(new JProperty("shape", shapItem));
                // compData.properties.Add("shape", shapItem);

                shapItem.SetEnum("shapeType", comp.shape.shapeType);
                shapItem.SetNumber("angle", comp.shape.angle);
                shapItem.SetNumber("length", comp.shape.length);
                shapItem.SetEnum("arcMode", comp.shape.arcMode);
                shapItem.SetNumber("arc", comp.shape.arc);
                shapItem.SetNumber("arcSpread", comp.shape.arcSpread);
                shapItem.SetEnum("radiusMode", comp.shape.radiusMode);
                shapItem.SetNumber("radius", comp.shape.radius);
                shapItem.SetNumber("radiusSpread", comp.shape.radiusSpread);
                shapItem.SetVector3("box", comp.shape.box);
                shapItem.SetBool("randomDirection", comp.shape.randomDirectionAmount > 0);
                shapItem.SetBool("spherizeDirection", comp.shape.sphericalDirectionAmount > 0);
                this.AddMinMaxCurve(shapItem, "arcSpeed", comp.shape.arcSpeed);
            }
            //velocityOverLifetiem
            if (comp.velocityOverLifetime.enabled)
            {
                var velocityOverItem = new JObject();
                compData.properties.Add(new JProperty("velocityOverLifetime", velocityOverItem));
                // compData.properties.Add("velocityOverLifetime", velocityOverItem);

                velocityOverItem.SetEnum("_mode", comp.velocityOverLifetime.x.mode);
                velocityOverItem.SetEnum("_space", comp.velocityOverLifetime.space);
                this.AddMinMaxCurve(velocityOverItem, "_x", comp.velocityOverLifetime.x);
                this.AddMinMaxCurve(velocityOverItem, "_y", comp.velocityOverLifetime.y);
                this.AddMinMaxCurve(velocityOverItem, "_z", comp.velocityOverLifetime.z);
            }
            //colorOverLifetime
            if (comp.colorOverLifetime.enabled)
            {
                var colorOverItem = new JObject();
                compData.properties.Add(new JProperty("colorOverLifetime", colorOverItem));
                // compData.properties.Add("colorOverLifetime", colorOverItem);

                this.AddMinMaxGradient(colorOverItem, "_color", comp.colorOverLifetime.color);
            }
            //sizeOverLifetime
            if (comp.sizeOverLifetime.enabled)
            {
                var sizeOverItem = new JObject();
                compData.properties.Add(new JProperty("sizeOverLifetime", sizeOverItem));
                // compData.properties.Add("sizeOverLifetime", sizeOverItem);

                sizeOverItem.SetBool("_separateAxes", comp.sizeOverLifetime.separateAxes);
                this.AddMinMaxCurve(sizeOverItem, "_size", comp.sizeOverLifetime.size);
                this.AddMinMaxCurve(sizeOverItem, "_x", comp.sizeOverLifetime.x);
                this.AddMinMaxCurve(sizeOverItem, "_y", comp.sizeOverLifetime.y);
                this.AddMinMaxCurve(sizeOverItem, "_z", comp.sizeOverLifetime.z);
            }
            //rotationOverLifetime
            if (comp.rotationOverLifetime.enabled)
            {
                var rotationOverItem = new JObject();
                compData.properties.Add(new JProperty("rotationOverLifetime", rotationOverItem));
                // compData.properties.Add("rotationOverLifetime", rotationOverItem);

                rotationOverItem.SetBool("_separateAxes", comp.rotationOverLifetime.separateAxes);
                this.AddMinMaxCurve(rotationOverItem, "_x", comp.rotationOverLifetime.x);
                this.AddMinMaxCurve(rotationOverItem, "_y", comp.rotationOverLifetime.y);
                this.AddMinMaxCurve(rotationOverItem, "_z", comp.rotationOverLifetime.z);
            }
            //textureSheetAnimationModule
            if (comp.textureSheetAnimation.enabled)
            {
                var textureSheetAnimation = new JObject();
                compData.properties.Add(new JProperty("textureSheetAnimation", textureSheetAnimation));
                // compData.properties.Add("textureSheetAnimation", textureSheetAnimation);

                textureSheetAnimation.SetInt("_numTilesX", comp.textureSheetAnimation.numTilesX);
                textureSheetAnimation.SetInt("_numTilesY", comp.textureSheetAnimation.numTilesY);
                textureSheetAnimation.SetEnum("_animation", comp.textureSheetAnimation.animation);
                textureSheetAnimation.SetBool("_useRandomRow", comp.textureSheetAnimation.useRandomRow);
                textureSheetAnimation.SetInt("_cycleCount", comp.textureSheetAnimation.cycleCount);
                textureSheetAnimation.SetInt("_rowIndex", comp.textureSheetAnimation.rowIndex);
                this.AddMinMaxCurve(textureSheetAnimation, "_frameOverTime", comp.textureSheetAnimation.frameOverTime, comp.textureSheetAnimation.numTilesX * comp.textureSheetAnimation.numTilesY);
                this.AddMinMaxCurve(textureSheetAnimation, "_startFrame", comp.textureSheetAnimation.startFrame);
            }
        }
コード例 #16
0
        public static void Serialize(GameObject obj)
        {
            //未激活的不导出
            if ((!ExportToolsSetting.instance.exportUnactivatedObject && !obj.activeInHierarchy))
            {
                MyLog.Log(obj.name + "对象未激活");
                return;
            }

            if (obj.GetComponent <RectTransform>() != null)
            {
                return;
            }
            MyLog.Log("导出对象:" + obj.name);
            MyJson_Object item = new MyJson_Object();

            item.SetUUID(obj.GetInstanceID().ToString());
            item.SetUnityID(obj.GetInstanceID());
            item.SetClass("paper.GameObject");
            item.SetString("name", obj.name);
            item.SetString("tag", obj.tag);
            var layerMask = 1 << obj.layer;

            item.SetInt("layer", layerMask);
            // item.SetInt("layer", LAYER[obj.layer >= LAYER.Length ? 0 : obj.layer]);;
            item.SetBool("isStatic", obj.isStatic);

            var componentsItem = new MyJson_Array();

            item["components"] = componentsItem;
            ResourceManager.instance.AddObjectJson(item);

            var components = obj.GetComponents <Component>();

            var index = 0;//TODO

            foreach (var comp in components)
            {
                if (comp is Animator)
                {
                    components[index] = components[0];
                    components[0]     = comp;
                }

                index++;
            }

            //遍历填充组件
            foreach (var comp in components)
            {
                if (comp == null)
                {
                    MyLog.LogWarning("空的组件");
                    continue;
                }
                string compClass = comp.GetType().Name;
                MyLog.Log("组件:" + compClass);
                if (!ExportToolsSetting.instance.exportUnactivatedComp)
                {
                    //利用反射查看组件是否激活,某些组件的enabled不再继承链上,只能用反射,比如BoxCollider
                    var property = comp.GetType().GetProperty("enabled");
                    if (property != null && !((bool)property.GetValue(comp, null)))
                    {
                        MyLog.Log(obj.name + "组件未激活");
                        continue;
                    }
                }

                if (!SerializeObject.IsComponentSupport(compClass))
                {
                    MyLog.LogWarning("不支持的组件: " + compClass);
                    continue;
                }
                if (SerializeObject.SerializedComponent(obj, compClass, comp))
                {
                    MyLog.Log("--导出组件:" + compClass);
                    componentsItem.AddHashCode(comp);
                }
                else
                {
                    MyLog.LogWarning("组件: " + compClass + " 导出失败");
                }
            }
            //遍历子对象
            if (obj.transform.childCount > 0)
            {
                for (int i = 0; i < obj.transform.childCount; i++)
                {
                    var child = obj.transform.GetChild(i).gameObject;
                    Serialize(child);
                }
            }
        }
コード例 #17
0
        public override void CollectUniformValues()
        {
            base.CollectUniformValues();
            var values = this.data.values;
            //自定义的value全部导出,不和默认值做过滤
            var target             = this.source;
            var materialProperties = MaterialEditor.GetMaterialProperties(new UnityEngine.Object[] { target });

            foreach (var materialProperty in materialProperties)
            {
                if (materialProperty.flags == MaterialProperty.PropFlags.HideInInspector)
                {
                    continue;
                }

                string type = materialProperty.type.ToString();
                if (type == "Float" || type == "Range")
                {
                    this.data.values.SetNumber(materialProperty.name, this.source.GetFloat(materialProperty.name, 0.0f), null);
                    // this.SetFloat(materialProperty.name, this.GetFloat(materialProperty.name, 0.0f), null);
                }
                else if (type == "Vector")
                {
                    this.data.values.SetVector4(materialProperty.name, this.source.GetVector4(materialProperty.name, Vector4.zero));
                }
                else if (type == "Color")
                {
                    this.data.values.SetColor(materialProperty.name, this.source.GetColor(materialProperty.name, Color.white));
                }
                else if (type == "Texture")
                {
                    var tex = this.source.GetTexture(materialProperty.name, null);
                    if (tex != null)
                    {
                        string texdim = materialProperty.textureDimension.ToString();
                        if (texdim == "Tex2D")
                        {
                            this.data.values.SetTexture(materialProperty.name, tex);

                            string propertyName = materialProperty.name + "_ST";
                            if (target.HasProperty(propertyName))
                            {
                                this.data.values.SetVector4(propertyName, this.source.GetVector4(propertyName, Vector4.zero));
                            }
                        }
                        else
                        {
                            throw new Exception("not suport texdim:" + texdim);
                        }
                    }
                }
                else
                {
                    throw new Exception("not support type: " + materialProperty.type);
                }
            }

            //
            this.shaderAsset = UnityEditor.AssetDatabase.GetAssetPath(this.source.shader) + ".json";
            MyLog.Log("自定义Shader:" + this.shaderAsset);
        }
コード例 #18
0
        public static EntityData SerializeEntity(GameObject obj)
        {
            //未激活的不导出
            if ((!ExportSetting.instance.common.exportUnactivatedObject && !obj.activeInHierarchy))
            {
                MyLog.Log(obj.name + "对象未激活");
                return(null);
            }

            if (obj.GetComponent <RectTransform>() != null)
            {
                return(null);
            }
            MyLog.Log("对象:" + obj.name);
            var entityData = currentData.CreateEntity();
            var components = obj.GetComponents <Component>();

            var index = 0;//TODO

            foreach (var comp in components)
            {
                if (comp is Animator)
                {
                    components[index] = components[0];
                    components[0]     = comp;
                }

                index++;
            }

            foreach (var comp in components)
            {
                if (comp == null)
                {
                    MyLog.LogWarning("空的组件");
                    continue;
                }
                string compClass = comp.GetType().Name;
                // MyLog.Log("组件:" + compClass);
                if (!ExportSetting.instance.common.exportUnactivatedComp)
                {
                    //利用反射查看组件是否激活,某些组件的enabled不再继承链上,只能用反射,比如BoxCollider
                    var property = comp.GetType().GetProperty("enabled");
                    if (property != null && !((bool)property.GetValue(comp, null)))
                    {
                        MyLog.Log(obj.name + "组件未激活");
                        continue;
                    }
                }

                if (!SerializeObject.IsComponentSupport(compClass))
                {
                    MyLog.LogWarning("不支持的组件: " + compClass);
                    continue;
                }
                var compData = SerializeObject.SerializeComponent(obj, compClass, comp, entityData);
                if (compData != null)
                {
                    entityData.AddComponent(compData);
                    MyLog.Log("--导出组件:" + compClass);
                }
                else
                {
                    MyLog.LogWarning("组件: " + compClass + " 导出失败");
                }
            }

            return(entityData);
        }
コード例 #19
0
        public static byte[] Export(Texture2D source)
        {
            var path           = AssetDatabase.GetAssetPath(source);
            var textureSetting = ExportSetting.instance.texture;

            MyLog.Log("---导出图片:" + source.name + " path:" + path);

            //只有jpg、png可以原始图片导出,其他类型不支持
            var fileName = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.dataPath), path);

            byte[] bs = null;
            if (textureSetting.useOriginalTexture && PathHelper.IsSupportedExt(source) && System.IO.File.Exists(fileName))
            {
                bs = System.IO.File.ReadAllBytes(fileName);
            }
            else
            {
                var saveTextureType = TextureImporterType.Default;
                var importer        = UnityEditor.TextureImporter.GetAtPath(path) as TextureImporter;
                if (importer)
                {
                    saveTextureType = importer.textureType;
                    if (saveTextureType == TextureImporterType.NormalMap && !textureSetting.useNormalTexture)
                    {
                        //法线贴图类型贴图因为Unity特殊处理过,如果要正常导出,就要转换一下类型
                        importer.textureType = TextureImporterType.Default;
                        importer.SaveAndReimport();
                    }
                }

                var renderTexture = RenderTexture.GetTemporary(source.width, source.height);
                Graphics.Blit(source, renderTexture);
                RenderTexture.active = renderTexture;
                var exportTexture = new Texture2D(source.width, source.height);
                exportTexture.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
                exportTexture.Apply();

                try
                {
                    string ext = PathHelper.GetTextureExt(source);
                    if (ext == "jpg" || ext == "jpeg")
                    {
                        bs = exportTexture.EncodeToJPG(textureSetting.jpgQuality);
                    }
                    // else if (ext == "exr")
                    // {
                    //     bs = exportTexture.EncodeToEXR();
                    // }
                    else
                    {
                        bs = exportTexture.EncodeToPNG();
                    }
                }
                catch (System.Exception e)
                {
                    MyLog.LogError(e.StackTrace);
                    MyLog.LogError("图片导出出错:" + path + " 请保证原始资源是可读写,非压缩文件");
                }

                if (importer && importer.textureType != saveTextureType)
                {
                    importer.textureType = saveTextureType;
                    importer.SaveAndReimport();
                }
            }

            return(bs);
        }
コード例 #20
0
        public MyJson_Tree Write()
        {
            this.Update();
            var customConfig = ExportConfig.instance.IsCustomShader(this.shaderName);
            //
            var materialItemJson = new MyJson_Tree();
            var extensions       = new MyJson_Tree();

            materialItemJson.Add("extensions", extensions);

            var KHR_techniques_webglJson = new MyJson_Tree();

            extensions.Add("KHR_techniques_webgl", KHR_techniques_webglJson);

            var paperJson = new MyJson_Tree();

            extensions.Add("paper", paperJson);

            var valuesJson = new MyJson_Tree();

            KHR_techniques_webglJson.Add("values", valuesJson);

            //
            var source     = this.source;
            var shaderName = source.shader.name.ToLower();

            MyLog.Log("Shader:" + shaderName);
            foreach (var value in this.values)
            {
                valuesJson.Add(value.Key, value.Value);
            }
            if (customConfig != null && !string.IsNullOrEmpty(customConfig.technique))
            {
                KHR_techniques_webglJson.SetString("technique", customConfig.technique);
            }
            else
            {
                KHR_techniques_webglJson.SetString("technique", this.technique);
            }
            //paper
            paperJson.SetInt("renderQueue", this.source.renderQueue);


            if (this.defines.Count > 0)
            {
                var definesJson = new MyJson_Array();
                foreach (var define in this.defines)
                {
                    definesJson.AddString(define);
                }
                paperJson.Add("defines", definesJson);
            }

            //
            //standard
            var isDoubleSide  = this.isDoubleSide;
            var isTransparent = this.isTransparent;

            var blend      = this.blendMode;
            var statesJson = new MyJson_Tree();
            var enable     = new MyJson_Array();

            if (isDoubleSide || blend != BlendMode.None || isTransparent || (customConfig != null && customConfig.enable != null))
            {
                //states
                paperJson.Add("states", statesJson);
                var functionsJson = new MyJson_Tree();
                statesJson.Add("enable", enable);
                statesJson.Add("functions", functionsJson);
                if (customConfig != null && customConfig.enable != null)
                {
                    foreach (var value in customConfig.enable)
                    {
                        enable.AddInt(value);
                    }
                    if (customConfig.blendEquationSeparate != null)
                    {
                        this.SetBlendEquationSeparate(functionsJson, customConfig.blendEquationSeparate);
                    }
                    if (customConfig.blendFuncSeparate != null)
                    {
                        this.SetBlendFuncSeparate(functionsJson, customConfig.blendFuncSeparate);
                    }
                    if (customConfig.frontFace != null)
                    {
                        this.SetFrontFace(functionsJson, customConfig.frontFace);
                    }
                    if (customConfig.cullFace != null)
                    {
                        this.SetCullFace(functionsJson, customConfig.cullFace);
                    }
                    if (customConfig.depthFunc != null)
                    {
                        this.SetDepthFunc(functionsJson, customConfig.depthFunc);
                    }
                    if (customConfig.depthMask != null)
                    {
                        this.SetDepthMask(functionsJson, customConfig.depthMask);
                    }
                }
                else
                {
                    this.SetBlend(enable, functionsJson, blend);
                    this.SetCullFace(enable, functionsJson, !isDoubleSide);
                    this.SetDepth(enable, functionsJson, true, !isTransparent);
                }
            }
            return(materialItemJson);
        }
コード例 #21
0
        // a mesh *might* decode to multiple prims if there are submeshes
        private MeshPrimitive[] ExportPrimitive(UnityEngine.Mesh meshObj, UnityEngine.Material[] materials, Skin skin = null)
        {
            MyLog.Log("Mesh属性:");
            var skinnedMeshRender = this._target.GetComponent <SkinnedMeshRenderer>();
            var root         = skinnedMeshRender ? this._target.transform : null;
            var materialsObj = new List <UnityEngine.Material>(materials);

            var prims = new MeshPrimitive[meshObj.subMeshCount];

            var byteOffset   = _bufferWriter.BaseStream.Position;
            var bufferViewId = this._root.WriteBufferView(this._bufferId, 0, (int)(_bufferWriter.BaseStream.Position - byteOffset));

            AccessorId aPosition = null, aNormal = null, aTangent = null,
                       aColor0 = null, aTexcoord0 = null, aTexcoord1 = null,
                       aBlendIndex = null, aBlendWeight = null;

            aPosition = this._root.WriteAccessor(this._bufferId, SchemaExtensions.ConvertVector3CoordinateSpaceAndCopy(meshObj.vertices, SchemaExtensions.CoordinateSpaceConversionScale), bufferViewId, false, null, this._bufferWriter);
            MyLog.Log("-------vertices:" + meshObj.vertices.Length);
            if (meshObj.normals.Length != 0 && (ExportSetting.instance.mesh.normal))
            {
                MyLog.Log("-------normals:" + meshObj.normals.Length);
                aNormal = this._root.WriteAccessor(this._bufferId, SchemaExtensions.ConvertVector3CoordinateSpaceAndCopy(meshObj.normals, SchemaExtensions.CoordinateSpaceConversionScale), bufferViewId, true, null, this._bufferWriter);
            }

            if (meshObj.tangents.Length != 0 && (ExportSetting.instance.mesh.tangent))
            {
                aTangent = this._root.WriteAccessor(this._bufferId, SchemaExtensions.ConvertVector4CoordinateSpaceAndCopy(meshObj.tangents, SchemaExtensions.TangentSpaceConversionScale), bufferViewId, true, this._bufferWriter);
            }

            if (meshObj.colors.Length != 0 && (ExportSetting.instance.mesh.color))
            {
                MyLog.Log("-------colors:" + meshObj.colors.Length);
                aColor0 = this._root.WriteAccessor(this._bufferId, meshObj.colors, bufferViewId, this._bufferWriter);
            }

            if (meshObj.uv.Length != 0)
            {
                MyLog.Log("-------uv:" + meshObj.uv.Length);
                aTexcoord0 = this._root.WriteAccessor(this._bufferId, SchemaExtensions.FlipTexCoordArrayVAndCopy(meshObj.uv), bufferViewId, this._bufferWriter);
            }

            var meshRender = this._target.GetComponent <MeshRenderer>();

            if (meshRender != null && meshRender.lightmapIndex >= 0)
            {
                MyLog.Log("-------uv2:" + meshObj.uv2.Length);
                aTexcoord1 = this._root.WriteAccessor(this._bufferId, SchemaExtensions.FlipTexCoordArrayVAndCopy(meshObj.uv2.Length > 0 ? meshObj.uv2 : meshObj.uv), bufferViewId, this._bufferWriter);
                // aTexcoord1 = ExportAccessor(ConvertLightMapUVAndCopy(meshObj.uv2.Length > 0 ? meshObj.uv2 : meshObj.uv, meshRender.lightmapScaleOffset), bufferViewId);
            }
            else
            {
                if (meshObj.uv2.Length != 0 && (ExportSetting.instance.mesh.uv2))
                {
                    MyLog.Log("-------uv2:" + meshObj.uv2.Length);
                    aTexcoord1 = this._root.WriteAccessor(this._bufferId, SchemaExtensions.FlipTexCoordArrayVAndCopy(meshObj.uv2), bufferViewId, this._bufferWriter);
                }
            }

            if (meshObj.boneWeights.Length != 0 && (ExportSetting.instance.mesh.bone))
            {
                MyLog.Log("-------bones:" + meshObj.boneWeights.Length);
                aBlendIndex  = this._root.WriteAccessor(this._bufferId, SchemaExtensions.ConvertBlendIndexAndCopy(meshObj.boneWeights), null, false, this._bufferWriter);
                aBlendWeight = this._root.WriteAccessor(this._bufferId, SchemaExtensions.ConvertBlendWeightAndCopy(meshObj.boneWeights), null, false, this._bufferWriter);
                if (skin != null)
                {
                    /*var index = 0;
                     * var renderer = _target.GetComponent<SkinnedMeshRenderer>();
                     * var bindposes = new Matrix4x4[renderer.bones.Length];
                     *
                     * foreach (var bone in renderer.bones)
                     * {
                     *  for (var i = 0; i < 16; ++i)
                     *  {
                     *      bindposes[index][i] = bone.worldToLocalMatrix[i];
                     *  }
                     *  index++;
                     * }
                     * skin.InverseBindMatrices = ExportAccessor(bindposes);*/
                    skin.InverseBindMatrices = this._root.WriteAccessor(this._bufferId, meshObj.bindposes, null, this._bufferWriter);
                }
            }

            this._root.BufferViews[bufferViewId.Id].ByteLength = (int)(this._bufferWriter.BaseStream.Position - byteOffset);


            MaterialId lastMaterialId = null;

            for (var submesh = 0; submesh < meshObj.subMeshCount; submesh++)
            {
                var primitive = new MeshPrimitive();

                var triangles = meshObj.GetTriangles(submesh);
                primitive.Indices = this._root.WriteAccessor(this._bufferId, SchemaExtensions.FlipFacesAndCopy(triangles), true, this._bufferWriter);

                primitive.Attributes = new Dictionary <string, AccessorId>();
                primitive.Attributes.Add(SemanticProperties.POSITION, aPosition);
                MyLog.Log("-------triangles:" + triangles.Length + "  submesh:" + submesh);
                if (aNormal != null)
                {
                    primitive.Attributes.Add(SemanticProperties.NORMAL, aNormal);
                }

                if (aTangent != null)
                {
                    primitive.Attributes.Add(SemanticProperties.TANGENT, aTangent);
                }

                if (aColor0 != null)
                {
                    primitive.Attributes.Add(SemanticProperties.Color(0), aColor0);
                }

                if (aTexcoord0 != null)
                {
                    primitive.Attributes.Add(SemanticProperties.TexCoord(0), aTexcoord0);
                }

                if (aTexcoord1 != null)
                {
                    primitive.Attributes.Add(SemanticProperties.TexCoord(1), aTexcoord1);
                }

                if (aBlendIndex != null && aBlendWeight != null)
                {
                    primitive.Attributes.Add(SemanticProperties.Joint(0), aBlendIndex);
                    primitive.Attributes.Add(SemanticProperties.Weight(0), aBlendWeight);
                }

                if (submesh < materialsObj.Count)
                {
                    primitive.Material = new MaterialId
                    {
                        Id   = materialsObj.IndexOf(materialsObj[submesh]),
                        Root = _root
                    };
                    lastMaterialId = primitive.Material;
                }
                else
                {
                    primitive.Material = lastMaterialId;
                }

                prims[submesh] = primitive;
            }

            return(prims);
        }
コード例 #22
0
        public override bool WriteToJson(GameObject obj, Component component, MyJson_Object compJson)
        {
            ParticleSystem comp = component as ParticleSystem;

            if (!comp.emission.enabled || obj.GetComponent <ParticleSystemRenderer>() == null)
            {
                MyLog.LogWarning("无效的粒子组件:" + obj.name);
                return(false);
            }

            //main
            {
                var main     = comp.main;
                var mainItem = new MyJson_Tree(false);
                compJson["main"] = mainItem;
                mainItem.SetNumber("duration", main.duration);
                mainItem.SetBool("loop", main.loop);
                this.AddMinMaxCurve(mainItem, "startDelay", main.startDelay);
                this.AddMinMaxCurve(mainItem, "startLifetime", main.startLifetime);
                this.AddMinMaxCurve(mainItem, "startSpeed", main.startSpeed);

                mainItem.SetBool("startSize3D", main.startSize3D);
                if (main.startSize3D)
                {
                    this.AddMinMaxCurve(mainItem, "startSizeX", main.startSizeX);
                    this.AddMinMaxCurve(mainItem, "startSizeY", main.startSizeY);
                    this.AddMinMaxCurve(mainItem, "startSizeZ", main.startSizeZ);
                }
                else
                {
                    this.AddMinMaxCurve(mainItem, "startSizeX", main.startSize);
                    this.AddMinMaxCurve(mainItem, "startSizeY", main.startSize);
                    this.AddMinMaxCurve(mainItem, "startSizeZ", main.startSize);
                }

                mainItem.SetBool("_startRotation3D", main.startRotation3D);
                if (main.startRotation3D)
                {
                    this.AddMinMaxCurve(mainItem, "startRotationX", main.startRotationX);
                    this.AddMinMaxCurve(mainItem, "startRotationY", main.startRotationY);
                    this.AddMinMaxCurve(mainItem, "startRotationZ", main.startRotationZ);
                }
                else
                {
                    this.AddMinMaxCurve(mainItem, "startRotationX", main.startRotation);
                    this.AddMinMaxCurve(mainItem, "startRotationY", main.startRotation);
                    this.AddMinMaxCurve(mainItem, "startRotationZ", main.startRotation);
                }

                this.AddMinMaxGradient(mainItem, "startColor", main.startColor);
                this.AddMinMaxCurve(mainItem, "gravityModifier", main.gravityModifier);
                mainItem.SetEnum("_simulationSpace", main.simulationSpace);
                mainItem.SetEnum("scaleMode", main.scalingMode);
                mainItem.SetBool("playOnAwake", main.playOnAwake);
                if (ExportToolsSetting.instance.estimateMaxParticles)
                {
                    var value = this.EstimateMaxParticles(comp);
                    mainItem.SetInt("_maxParticles", value);
                    MyLog.Log(comp.gameObject.name + " 粒子估算:" + value);
                }
                else
                {
                    mainItem.SetInt("_maxParticles", main.maxParticles);
                }
            }

            //emission
            {
                var emissionItem = new MyJson_Tree(false);
                compJson["emission"] = emissionItem;
                this.AddMinMaxCurve(emissionItem, "rateOverTime", comp.emission.rateOverTime);
                emissionItem["bursts"] = new MyJson_Array();
                var bursts = new ParticleSystem.Burst[comp.emission.burstCount];
                comp.emission.GetBursts(bursts);
                foreach (var burst in bursts)
                {
                    MyJson_Array burstItem = new MyJson_Array();
                    burstItem.AddNumber(burst.time);
                    burstItem.AddInt(burst.minCount);
                    burstItem.AddInt(burst.maxCount);
                    burstItem.AddInt(burst.cycleCount);
                    burstItem.AddNumber(burst.repeatInterval);
                    (emissionItem["bursts"] as MyJson_Array).Add(burstItem);
                }
            }
            //shape
            if (comp.shape.enabled)
            {
                var shapItem = new MyJson_Tree(false);
                compJson["shape"] = shapItem;
                shapItem.SetEnum("shapeType", comp.shape.shapeType);
                shapItem.SetNumber("angle", comp.shape.angle);
                shapItem.SetNumber("length", comp.shape.length);
                shapItem.SetEnum("arcMode", comp.shape.arcMode);
                shapItem.SetNumber("arc", comp.shape.arc);
                shapItem.SetNumber("arcSpread", comp.shape.arcSpread);
                shapItem.SetEnum("radiusMode", comp.shape.radiusMode);
                shapItem.SetNumber("radius", comp.shape.radius);
                shapItem.SetNumber("radiusSpread", comp.shape.radiusSpread);
                shapItem.SetVector3("box", comp.shape.box);
                shapItem.SetBool("randomDirection", comp.shape.randomDirectionAmount > 0);
                shapItem.SetBool("spherizeDirection", comp.shape.sphericalDirectionAmount > 0);
                this.AddMinMaxCurve(shapItem, "arcSpeed", comp.shape.arcSpeed);
            }
            //velocityOverLifetiem
            if (comp.velocityOverLifetime.enabled)
            {
                var velocityOverItem = new MyJson_Tree(false);
                compJson["velocityOverLifetime"] = velocityOverItem;
                velocityOverItem.SetEnum("_mode", comp.velocityOverLifetime.x.mode);
                velocityOverItem.SetEnum("_space", comp.velocityOverLifetime.space);
                this.AddMinMaxCurve(velocityOverItem, "_x", comp.velocityOverLifetime.x);
                this.AddMinMaxCurve(velocityOverItem, "_y", comp.velocityOverLifetime.y);
                this.AddMinMaxCurve(velocityOverItem, "_z", comp.velocityOverLifetime.z);
            }
            //colorOverLifetime
            if (comp.colorOverLifetime.enabled)
            {
                var colorOverItem = new MyJson_Tree(false);
                compJson["colorOverLifetime"] = colorOverItem;
                this.AddMinMaxGradient(colorOverItem, "_color", comp.colorOverLifetime.color);
            }
            //sizeOverLifetime
            if (comp.sizeOverLifetime.enabled)
            {
                var sizeOverItem = new MyJson_Tree(false);
                compJson["sizeOverLifetime"] = sizeOverItem;
                sizeOverItem.SetBool("_separateAxes", comp.sizeOverLifetime.separateAxes);
                this.AddMinMaxCurve(sizeOverItem, "_size", comp.sizeOverLifetime.size);
                this.AddMinMaxCurve(sizeOverItem, "_x", comp.sizeOverLifetime.x);
                this.AddMinMaxCurve(sizeOverItem, "_y", comp.sizeOverLifetime.y);
                this.AddMinMaxCurve(sizeOverItem, "_z", comp.sizeOverLifetime.z);
            }
            //rotationOverLifetime
            if (comp.rotationOverLifetime.enabled)
            {
                var rotationOverItem = new MyJson_Tree(false);
                compJson["rotationOverLifetime"] = rotationOverItem;
                rotationOverItem.SetBool("_separateAxes", comp.rotationOverLifetime.separateAxes);
                this.AddMinMaxCurve(rotationOverItem, "_x", comp.rotationOverLifetime.x);
                this.AddMinMaxCurve(rotationOverItem, "_y", comp.rotationOverLifetime.y);
                this.AddMinMaxCurve(rotationOverItem, "_z", comp.rotationOverLifetime.z);
            }
            //textureSheetAnimationModule
            if (comp.textureSheetAnimation.enabled)
            {
                var textureSheetAnimation = new MyJson_Tree(false);
                compJson["textureSheetAnimation"] = textureSheetAnimation;
                textureSheetAnimation.SetInt("_numTilesX", comp.textureSheetAnimation.numTilesX);
                textureSheetAnimation.SetInt("_numTilesY", comp.textureSheetAnimation.numTilesY);
                textureSheetAnimation.SetEnum("_animation", comp.textureSheetAnimation.animation);
                textureSheetAnimation.SetBool("_useRandomRow", comp.textureSheetAnimation.useRandomRow);
                textureSheetAnimation.SetInt("_cycleCount", comp.textureSheetAnimation.cycleCount);
                textureSheetAnimation.SetInt("_rowIndex", comp.textureSheetAnimation.rowIndex);
                this.AddMinMaxCurve(textureSheetAnimation, "_frameOverTime", comp.textureSheetAnimation.frameOverTime, comp.textureSheetAnimation.numTilesX * comp.textureSheetAnimation.numTilesY);
                this.AddMinMaxCurve(textureSheetAnimation, "_startFrame", comp.textureSheetAnimation.startFrame);
            }

            return(true);
        }