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); }
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); } }
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); }
// 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); }
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); }
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); }