protected override JSONObject ToJSON(WXHierarchyContext context) { JSONObject json = new JSONObject(JSONObject.Type.OBJECT); json.AddField("type", "UILabel"); JSONObject subJSON = new JSONObject(JSONObject.Type.OBJECT); string str = uiLabel.text.Replace("\r\n", "\\n").Replace("\\", "\\\\").Replace("\"", "\\\""); subJSON.AddField("text", str); subJSON.AddField("fontSize", uiLabel.fontSize); int instanceID = 0; string fontFamily = ""; if (uiLabel.trueTypeFont) { // NGUI font instanceID = uiLabel.trueTypeFont.material.GetInstanceID(); string path = AssetDatabase.GetAssetPath(instanceID); // 相对路径 if (path.IndexOf("Library") != 0) { // Debug.Log(fontFamily); WXFont fontConverter = new WXFont(path); fontFamily = fontConverter.Export(context.preset); context.AddResource(fontFamily); } else { string name = this.uiLabel.gameObject.name; Debug.LogWarning("UI Label:" + name + " use system font!!"); } } else if (uiLabel.bitmapFont) { fontFamily = ""; WXBitmapFont bitmapFont = new WXBitmapFont(uiLabel.bitmapFont); string path = bitmapFont.Export(context.preset); context.AddResource(path); subJSON.AddField("bitmapFont", path); } if (fontFamily != "") { subJSON.AddField("font", fontFamily); } string fontStyle = uiLabel.fontStyle.ToString(); subJSON.AddField("bold", fontStyle == "Bold" || fontStyle == "Bold And Italic"); subJSON.AddField("italic", fontStyle == "Italic" || fontStyle == "Bold And Italic"); int alignment = 0; switch (uiLabel.alignment.ToString()) { case "Left": alignment = 1; break; case "Center": alignment = 2; break; case "Right": alignment = 3; break; default: alignment = 0; string rawPivot = uiLabel.rawPivot.ToString(); switch (rawPivot) { case "Left": alignment = 1; break; case "Center": alignment = 2; break; case "Right": alignment = 3; break; } break; } subJSON.AddField("align", alignment); // 应轩辕要求,缺省值改成 2 int valign = 2; string pivot = uiLabel.pivot.ToString(); switch (pivot) { case "Top": valign = 1; break; case "Center": valign = 2; break; case "Bottom": valign = 3; break; default: valign = 2; break; } subJSON.AddField("valign", valign); if (uiLabel.effectStyle != UILabel.Effect.None) { JSONObject c = new JSONObject(JSONObject.Type.ARRAY); c.Add(255f * uiLabel.effectColor.r); c.Add(255f * uiLabel.effectColor.g); c.Add(255f * uiLabel.effectColor.b); c.Add(255f * uiLabel.effectColor.a); switch (uiLabel.effectStyle) { case UILabel.Effect.None: break; case UILabel.Effect.Shadow: JSONObject v2 = new JSONObject(JSONObject.Type.ARRAY); v2.Add(uiLabel.effectDistance.x); v2.Add(uiLabel.effectDistance.y); subJSON.AddField("shadowOffset", v2); subJSON.AddField("shadowColor", c); break; case UILabel.Effect.Outline8: subJSON.AddField("strokeColor", c); subJSON.AddField("stroke", uiLabel.effectDistance.x); break; case UILabel.Effect.Outline: subJSON.AddField("strokeColor", c); subJSON.AddField("stroke", uiLabel.effectDistance.x); break; default: break; } } subJSON.AddField("spacing", uiLabel.spacingX); JSONObject color = new JSONObject(JSONObject.Type.ARRAY); color.Add(255f * uiLabel.color.r); color.Add(255f * uiLabel.color.g); color.Add(255f * uiLabel.color.b); color.Add(255f * uiLabel.color.a); subJSON.AddField("fontColor", color); subJSON.AddField("colorBlendType", 0); subJSON.AddField("applyGradient", uiLabel.applyGradient); JSONObject topColor = new JSONObject(JSONObject.Type.ARRAY); JSONObject bottomColor = new JSONObject(JSONObject.Type.ARRAY); topColor.Add(255f * uiLabel.gradientTop.r); topColor.Add(255f * uiLabel.gradientTop.g); topColor.Add(255f * uiLabel.gradientTop.b); topColor.Add(255f * uiLabel.gradientTop.a); bottomColor.Add(255f * uiLabel.gradientBottom.r); bottomColor.Add(255f * uiLabel.gradientBottom.g); bottomColor.Add(255f * uiLabel.gradientBottom.b); bottomColor.Add(255f * uiLabel.gradientBottom.a); subJSON.AddField("gradientTop", topColor); subJSON.AddField("gradientBottom", bottomColor); subJSON.AddField("active", uiLabel.enabled); json.AddField("data", subJSON); return(json); }
protected override void DoExport() { EditorUtility.ClearProgressBar(); BridgeExport.isProcessing = false; List <string> allRecursiveAssets = new List <string>(); // string choosedPath = GetExportPath(); // string savePath = Path.Combine(choosedPath, "Assets/"); var savePath = Path.Combine(ExportStore.storagePath, "Assets/"); updateRecourcesDir(); int totalCount = 0; string [] arr_dir = dirs.ToArray(); JSONObject jsonConfig = new JSONObject(JSONObject.Type.ARRAY); if (arr_dir.Length > 0) { for (int index = 0; index < supportedTypes.Length; index++) { string filter = "t:" + supportedTypes[index]; string[] guids = AssetDatabase.FindAssets(filter, arr_dir); // Debug.Log(guids.Length); if (guids.Length == 0) { continue; } JSONObject category = new JSONObject(JSONObject.Type.OBJECT); JSONObject data = new JSONObject(JSONObject.Type.ARRAY); category.AddField("type", supportedTypes[index]); category.AddField("files", data); var t = 0; HashSet <string> setFiles = new HashSet <string>(); for (int i = 0; i < guids.Length; i++) { string path = AssetDatabase.GUIDToAssetPath(guids[i]); if (path.StartsWith("Assets")) { path = path.Substring(6); } string absolutePath = Path.Combine(Application.dataPath, path); // #if UNITY_EDITOR_WIN // string absolutePath = Application.dataPath + "\\" + path; // #else // string absolutePath = Application.dataPath + "/" + path; // #endif // string filename = System.IO.Path.GetFileName(absolutePath); string copyToPath = Path.Combine(savePath, path); // #if UNITY_EDITOR_WIN // string copyToPath = savePath + "\\" + path; // #else // string copyToPath = savePath + "/" + path; // #endif string extension = System.IO.Path.GetExtension(path); if (setExclude.Contains(extension)) { continue; } if (supportedTypes[index] != "GameObject") { #if USE_RAW_MODE string projpath = "Assets" + path; WXRawResource rawResource = new WXRawResource(projpath); string ret_path = rawResource.Export(this); allRecursiveAssets.Add(ret_path); #else wxFileUtil.CopyFile(absolutePath, copyToPath); #endif } JSONObject fileInfo = new JSONObject(JSONObject.Type.OBJECT); // fileInfo.AddField("key", Path.GetFileNameWithoutExtension(filename)); string key = getResourcePath(path); if (setFiles.Contains(key)) { continue; } else { setFiles.Add(key); } fileInfo.AddField("key", key); fileInfo.AddField("name", "Assets" + path); data.Add(fileInfo); totalCount++; EditorUtility.DisplayProgressBar("原始资源导出", "", t++ / guids.Length); } jsonConfig.Add(category); } } #if USE_RAW_MODE string tempConfigFile = Path.Combine(Application.dataPath, "Resources.json"); wxFileUtil.SaveJsonFile(jsonConfig, tempConfigFile); string configpath = "Assets/Resources.json"; WXRawResource rawConfig = new WXRawResource(configpath); string ret_cfg_path = rawConfig.Export(this); allRecursiveAssets.Add(ret_cfg_path); File.Delete(tempConfigFile); #endif // string content = jsonConfig.ToString(); // ExportStore.AddTextFile(configpath, content, WXUtility.GetMD5FromString(content)); // List<string> useConfig = new List<string>(); // useConfig.Add(configpath); // ExportStore.AddResource(configpath, "raw", null, useConfig); // allRecursiveAssets.Add(configpath); ExportStore.GenerateResourcePackage( "WXResources", allRecursiveAssets ); EditorUtility.ClearProgressBar(); Debug.Log("导出成功,总共导出文件个数:" + totalCount); }
protected override JSONObject ToJSON(WXHierarchyContext context) { JSONObject json = new JSONObject(JSONObject.Type.OBJECT); json.AddField("type", getTypeName()); JSONObject subJSON = new JSONObject(JSONObject.Type.OBJECT); string str = uiLabel.text; subJSON.AddField("text", str); subJSON.AddField("fontSize", uiLabel.fontSize); JSONObject color = new JSONObject(JSONObject.Type.ARRAY); color.Add(255f * uiLabel.color.r); color.Add(255f * uiLabel.color.g); color.Add(255f * uiLabel.color.b); color.Add(255f * uiLabel.color.a); subJSON.AddField("fontColor", color); int instanceID = 0; string fontFamily = ""; if (uiLabel.font) { // NGUI font instanceID = uiLabel.font.material.GetInstanceID(); string path = AssetDatabase.GetAssetPath(instanceID); // 相对路径 if (path.IndexOf("Library") != 0) { // Debug.Log(fontFamily); WXUGUIFont fontConverter = new WXUGUIFont(path); fontFamily = fontConverter.Export(context.preset); context.AddResource(fontFamily); } else { string name = this.uiLabel.gameObject.name; Debug.LogWarning("UI Label:" + name + " use system font!!"); } } if (fontFamily != "") { subJSON.AddField("font", fontFamily); } int alignment = 0; if (uiLabel.alignment == TextAnchor.LowerLeft || uiLabel.alignment == TextAnchor.MiddleLeft || uiLabel.alignment == TextAnchor.UpperLeft) { alignment = 1; } else if (uiLabel.alignment == TextAnchor.LowerCenter || uiLabel.alignment == TextAnchor.MiddleCenter || uiLabel.alignment == TextAnchor.UpperCenter) { alignment = 2; } else if (uiLabel.alignment == TextAnchor.LowerRight || uiLabel.alignment == TextAnchor.MiddleRight || uiLabel.alignment == TextAnchor.UpperRight) { alignment = 3; } subJSON.AddField("align", alignment); int valign = 0; if (uiLabel.alignment == TextAnchor.LowerLeft || uiLabel.alignment == TextAnchor.LowerCenter || uiLabel.alignment == TextAnchor.LowerRight) { valign = 3; } else if (uiLabel.alignment == TextAnchor.MiddleLeft || uiLabel.alignment == TextAnchor.MiddleCenter || uiLabel.alignment == TextAnchor.MiddleRight) { valign = 2; } else if (uiLabel.alignment == TextAnchor.UpperLeft || uiLabel.alignment == TextAnchor.UpperCenter || uiLabel.alignment == TextAnchor.UpperRight) { valign = 1; } subJSON.AddField("valign", valign); //switch (uiLabel.alignment.ToString()) //{ //} //if(uiLabel.) subJSON.AddField("active", uiLabel.IsActive()); json.AddField("data", subJSON); return(json); }
protected override JSONObject ExportResource(ExportPreset preset) { // 搞配置 string[] lines = System.IO.File.ReadAllLines(unityAssetPath); string pattern = @"^\s+"; JSONObject bitmapFontResource = new JSONObject(JSONObject.Type.OBJECT); JSONObject bitmapFontConfig = new JSONObject(JSONObject.Type.OBJECT); JSONObject currentcharacterConfig = null; string currentIndex = ""; for (int i = 0; i < lines.Length; i++) { string line = Regex.Replace(lines[i], pattern, ""); if (line.StartsWith("mSize")) { string[] array = line.Split(':'); int lineHeight = Int32.Parse(array[1].Trim()); bitmapFontResource.AddField("lineHeight", lineHeight); } else if (line.StartsWith("mBase")) { string[] array = line.Split(':'); int fontSize = Int32.Parse(array[1].Trim()); bitmapFontResource.AddField("fontSize", fontSize); } else if (line.StartsWith("mWidth")) { string[] array = line.Split(':'); int width = Int32.Parse(array[1].Trim()); bitmapFontResource.AddField("width", width); } else if (line.StartsWith("mHeight")) { string[] array = line.Split(':'); int height = Int32.Parse(array[1].Trim()); bitmapFontResource.AddField("height", height); } if (line.StartsWith("- index")) { if (currentcharacterConfig) { bitmapFontConfig.AddField(currentIndex, currentcharacterConfig); currentcharacterConfig = null; } JSONObject characterConfig = new JSONObject(JSONObject.Type.OBJECT); string index = line.Replace("- index: ", ""); currentcharacterConfig = characterConfig; currentIndex = index; } else if (currentcharacterConfig) { string[] array = line.Split(':'); string key = array[0].Trim(); if (key == "x" || key == "y" || key == "width" || key == "height" || key == "offsetX" || key == "offsetY" || key == "advance" || key == "channel") { int value = Int32.Parse(array[1].Trim()); currentcharacterConfig.AddField(key, value); } } } if (currentcharacterConfig) { bitmapFontConfig.AddField(currentIndex, currentcharacterConfig); } Texture2D unityTexture = _bitmapFont.material.mainTexture as Texture2D; string wxbbTextureID = AddDependencies(new WXTexture(unityTexture)); List <string> dependencyResource = new List <string>(); dependencyResource.Add(wxbbTextureID); bitmapFontResource.AddField("frames", bitmapFontConfig); bitmapFontResource.AddField("texture", wxbbTextureID); bitmapFontResource.AddField("version", 2); return(bitmapFontResource); }
protected override JSONObject ToJSON(WXHierarchyContext context) { Debug.Log("Particle System ToJSON"); ParticleSystemRenderer particleSystemRenderer = particleSys.GetComponent <ParticleSystemRenderer>(); JSONObject json = new JSONObject(JSONObject.Type.OBJECT); JSONObject data = new JSONObject(JSONObject.Type.OBJECT); json.AddField("type", getTypeName()); json.AddField("data", data); JSONObject materials = new JSONObject(JSONObject.Type.ARRAY); data.AddField("materials", materials); Material[] mats = particleSystemRenderer.sharedMaterials; foreach (Material material in mats) { if (material != null) { WXMaterial materialConverter = new WXMaterial(material, particleSystemRenderer); string materialPath = materialConverter.Export(context.preset); materials.Add(materialPath); context.AddResource(materialPath); } } JSONObject modCommon = new JSONObject(JSONObject.Type.OBJECT); JSONObject modCommonData = new JSONObject(JSONObject.Type.OBJECT); data.AddField("common", modCommonData); modCommonData.AddField("startSize3D", particleSys.main.startSize3D); if (particleSys.main.startSize3D) { modCommonData.AddField("startSizeX", ParseMinMaxCurve(particleSys.main.startSizeX)); modCommonData.AddField("startSizeY", ParseMinMaxCurve(particleSys.main.startSizeY)); modCommonData.AddField("startSizeZ", ParseMinMaxCurve(particleSys.main.startSizeZ)); } else { modCommonData.AddField("startSize", ParseMinMaxCurve(particleSys.main.startSize)); } modCommonData.AddField("startColor", ParseMinMaxGradient(particleSys.main.startColor)); modCommonData.AddField("startLifetime", ParseMinMaxCurve(particleSys.main.startLifetime)); modCommonData.AddField("startRotation3D", particleSys.main.startRotation3D); if (particleSys.main.startRotation3D) { modCommonData.AddField("startRotationX", ParseMinMaxCurve(particleSys.main.startRotationX, (float)(180 / Math.PI))); modCommonData.AddField("startRotationY", ParseMinMaxCurve(particleSys.main.startRotationY, (float)(180 / Math.PI))); modCommonData.AddField("startRotationZ", ParseMinMaxCurve(particleSys.main.startRotationZ, (float)(180 / Math.PI))); } else { modCommonData.AddField("startRotationZ", ParseMinMaxCurve(particleSys.main.startRotation, (float)(180 / Math.PI))); } modCommonData.AddField("startSpeed", ParseMinMaxCurve(particleSys.main.startSpeed)); modCommonData.AddField("gravityModifier", ParseMinMaxCurve(particleSys.main.gravityModifier)); #if UNITY_2018_1_OR_NEWER modCommonData.AddField("randomizeRotation", particleSys.main.flipRotation); #endif modCommonData.AddField("randomSeed", particleSys.randomSeed); modCommonData.AddField("autoRandomSeed", particleSys.useAutoRandomSeed); ParticleSystemScalingMode pScalingMode = particleSys.main.scalingMode; int pScalingModeNum = 0; switch (pScalingMode) { case ParticleSystemScalingMode.Hierarchy: pScalingModeNum = 0; break; case ParticleSystemScalingMode.Local: pScalingModeNum = 1; break; case ParticleSystemScalingMode.Shape: pScalingModeNum = 2; break; } modCommonData.AddField("scalingMode", pScalingModeNum); ParticleSystemSimulationSpace simulationSpace = particleSys.main.simulationSpace; int simulationSpaceNum = 0; switch (simulationSpace) { case ParticleSystemSimulationSpace.Local: simulationSpaceNum = 0; break; case ParticleSystemSimulationSpace.World: simulationSpaceNum = 1; break; case ParticleSystemSimulationSpace.Custom: simulationSpaceNum = 2; break; } modCommonData.AddField("simulationSpace", simulationSpaceNum); JSONObject emitter = new JSONObject(JSONObject.Type.OBJECT); JSONObject emitterData = new JSONObject(JSONObject.Type.OBJECT); data.AddField("emitter", emitterData); emitterData.AddField("playOnAwake", particleSys.main.playOnAwake); emitterData.AddField("looping", particleSys.main.loop); emitterData.AddField("duration", particleSys.main.duration); emitterData.AddField("startDelay", ParseMinMaxCurve(particleSys.main.startDelay)); if (particleSys.emission.enabled) { JSONObject burst = new JSONObject(JSONObject.Type.ARRAY); emitterData.AddField("bursts", burst); int count = particleSys.emission.burstCount; ParticleSystem.Burst[] bursts = new ParticleSystem.Burst[count]; particleSys.emission.GetBursts(bursts); for (int i = 0; i < count; i++) { //burst.Add(ParseBurst(particleSys.emission.GetBurst(i))); burst.Add(ParseBurst(bursts[i])); } emitterData.AddField("rateOverTime", ParseMinMaxCurve(particleSys.emission.rateOverTime)); } emitterData.AddField("maxParticles", particleSys.main.maxParticles); if (particleSystemRenderer.enabled) { JSONObject renderer = new JSONObject(JSONObject.Type.OBJECT); JSONObject rendererData = new JSONObject(JSONObject.Type.OBJECT); data.AddField("renderer", rendererData); ParticleSystemRenderMode pRenderMode = particleSystemRenderer.renderMode; int pRenderModeNum = 0; switch (pRenderMode) { case ParticleSystemRenderMode.Billboard: pRenderModeNum = 1; break; case ParticleSystemRenderMode.Stretch: pRenderModeNum = 2; rendererData.AddField("cameraScale", particleSystemRenderer.cameraVelocityScale); rendererData.AddField("speedScale", particleSystemRenderer.velocityScale); rendererData.AddField("lengthScale", particleSystemRenderer.lengthScale); break; case ParticleSystemRenderMode.HorizontalBillboard: pRenderModeNum = 3; break; case ParticleSystemRenderMode.VerticalBillboard: pRenderModeNum = 4; break; case ParticleSystemRenderMode.Mesh: Mesh mesh = particleSystemRenderer.mesh; if (mesh != null) { WXMesh meshConverter = new WXMesh(mesh); string meshPath = meshConverter.Export(context.preset); rendererData.AddField("mesh", meshPath); rendererData.AddField("meshCount", particleSystemRenderer.meshCount); context.AddResource(meshPath); } else { Debug.LogError(string.Format("{0} mesh is null", particleSys.name)); } pRenderModeNum = 5; break; case ParticleSystemRenderMode.None: pRenderModeNum = 0; break; default: pRenderModeNum = 1; break; } rendererData.AddField("renderMode", pRenderModeNum); int mode = 1; switch (particleSystemRenderer.alignment) { case ParticleSystemRenderSpace.View: mode = 1; break; case ParticleSystemRenderSpace.World: mode = 2; break; case ParticleSystemRenderSpace.Local: mode = 3; break; case ParticleSystemRenderSpace.Facing: mode = 4; break; #if UNITY_2017_1_OR_NEWER case ParticleSystemRenderSpace.Velocity: mode = 5; break; #endif default: break; } rendererData.AddField("renderAlignment", mode); mode = 0; switch (particleSystemRenderer.sortMode) { case ParticleSystemSortMode.None: mode = 0; break; case ParticleSystemSortMode.Distance: mode = 1; break; case ParticleSystemSortMode.OldestInFront: mode = 2; break; case ParticleSystemSortMode.YoungestInFront: mode = 3; break; default: break; } rendererData.AddField("sortMode", mode); rendererData.AddField("sortingFudge", particleSystemRenderer.sortingFudge); rendererData.AddField("normalDirection", particleSystemRenderer.normalDirection); rendererData.AddField("minParticleSize", particleSystemRenderer.minParticleSize); rendererData.AddField("maxParticleSize", particleSystemRenderer.maxParticleSize); var flipValue = TryGetContainProperty(particleSystemRenderer, "flip"); if (flipValue != null) { rendererData.AddField("flip", GetVect3((Vector3)flipValue)); } else { renderer.AddField("flip", GetVect3(new Vector3(0, 0, 0))); } //rendererData.AddField("flip", GetVect3(particleSystemRenderer.flip)); rendererData.AddField("pivot", GetVect3(particleSystemRenderer.pivot)); var allowRollData = TryGetContainProperty(particleSystemRenderer, "allowRoll"); if (allowRollData != null) { rendererData.AddField("allowRoll", (bool)allowRollData); } else { rendererData.AddField("allowRoll", false); } } else { String info = "entity: " + particleSys.gameObject.name + " 的粒子组件没有renderer模块,不可导出;请加上renderer模块,或删除该粒子组件"; ErrorUtil.ExportErrorReporter.create() .setGameObject(particleSys.gameObject) .setHierarchyContext(context) .error(ErrorUtil.ErrorCode.Particle_RendererNotFound, "粒子组件没有renderer模块,不可导出;请加上renderer模块,或删除该粒子组件"); } if (particleSys.rotationOverLifetime.enabled) { JSONObject rotationByLife = new JSONObject(JSONObject.Type.OBJECT); JSONObject rotationByLifeData = new JSONObject(JSONObject.Type.OBJECT); data.AddField("rotationByLife", rotationByLifeData); rotationByLifeData.AddField("separateAxes", particleSys.rotationOverLifetime.separateAxes); if (particleSys.rotationOverLifetime.separateAxes) { rotationByLifeData.AddField("x", ParseMinMaxCurve(particleSys.rotationOverLifetime.x, (float)(180 / Math.PI))); rotationByLifeData.AddField("y", ParseMinMaxCurve(particleSys.rotationOverLifetime.y, (float)(180 / Math.PI))); rotationByLifeData.AddField("z", ParseMinMaxCurve(particleSys.rotationOverLifetime.z, (float)(180 / Math.PI))); } else { rotationByLifeData.AddField("z", ParseMinMaxCurve(particleSys.rotationOverLifetime.z, (float)(180 / Math.PI))); } } if (particleSys.sizeOverLifetime.enabled) { JSONObject sizeOverLifetime = new JSONObject(JSONObject.Type.OBJECT); JSONObject sizeOverLifetimeData = new JSONObject(JSONObject.Type.OBJECT); data.AddField("sizeByLife", sizeOverLifetimeData); sizeOverLifetimeData.AddField("separateAxes", particleSys.sizeOverLifetime.separateAxes); if (particleSys.sizeOverLifetime.separateAxes) { sizeOverLifetimeData.AddField("x", ParseMinMaxCurve(particleSys.sizeOverLifetime.x)); sizeOverLifetimeData.AddField("y", ParseMinMaxCurve(particleSys.sizeOverLifetime.y)); sizeOverLifetimeData.AddField("z", ParseMinMaxCurve(particleSys.sizeOverLifetime.z)); } else { sizeOverLifetimeData.AddField("x", ParseMinMaxCurve(particleSys.sizeOverLifetime.size)); } } if (particleSys.velocityOverLifetime.enabled) { JSONObject speedByLifeData = new JSONObject(JSONObject.Type.OBJECT); data.AddField("speedByLife", speedByLifeData); switch (particleSys.velocityOverLifetime.space) { case ParticleSystemSimulationSpace.Local: speedByLifeData.AddField("space", 1); break; case ParticleSystemSimulationSpace.World: speedByLifeData.AddField("space", 2); break; case ParticleSystemSimulationSpace.Custom: break; default: break; } speedByLifeData.AddField("x", ParseMinMaxCurve(particleSys.velocityOverLifetime.x)); speedByLifeData.AddField("y", ParseMinMaxCurve(particleSys.velocityOverLifetime.y)); speedByLifeData.AddField("z", ParseMinMaxCurve(particleSys.velocityOverLifetime.z)); #if UNITY_2018_1_OR_NEWER speedByLifeData.AddField("orbitalX", ParseMinMaxCurve(particleSys.velocityOverLifetime.orbitalX)); speedByLifeData.AddField("orbitalY", ParseMinMaxCurve(particleSys.velocityOverLifetime.orbitalY)); speedByLifeData.AddField("orbitalZ", ParseMinMaxCurve(particleSys.velocityOverLifetime.orbitalZ)); speedByLifeData.AddField("orbitalOffsetX", ParseMinMaxCurve(particleSys.velocityOverLifetime.orbitalOffsetX)); speedByLifeData.AddField("orbitalOffsetY", ParseMinMaxCurve(particleSys.velocityOverLifetime.orbitalOffsetY)); speedByLifeData.AddField("orbitalOffsetZ", ParseMinMaxCurve(particleSys.velocityOverLifetime.orbitalOffsetZ)); speedByLifeData.AddField("radial", ParseMinMaxCurve(particleSys.velocityOverLifetime.radial)); #endif #if UNITY_2017_1_OR_NEWER speedByLifeData.AddField("speedScale", ParseMinMaxCurve(particleSys.velocityOverLifetime.speedModifier)); #endif } if (particleSys.limitVelocityOverLifetime.enabled) { JSONObject speedLimitByLifeData = new JSONObject(JSONObject.Type.OBJECT); data.AddField("speedLimitByLife", speedLimitByLifeData); speedLimitByLifeData.AddField("separateAxes", particleSys.limitVelocityOverLifetime.separateAxes); if (particleSys.limitVelocityOverLifetime.separateAxes) { speedLimitByLifeData.AddField("x", ParseMinMaxCurve(particleSys.limitVelocityOverLifetime.limitX, particleSys.limitVelocityOverLifetime.limitXMultiplier)); speedLimitByLifeData.AddField("y", ParseMinMaxCurve(particleSys.limitVelocityOverLifetime.limitY, particleSys.limitVelocityOverLifetime.limitYMultiplier)); speedLimitByLifeData.AddField("z", ParseMinMaxCurve(particleSys.limitVelocityOverLifetime.limitZ, particleSys.limitVelocityOverLifetime.limitZMultiplier)); } else { speedLimitByLifeData.AddField("x", ParseMinMaxCurve(particleSys.limitVelocityOverLifetime.limit, particleSys.limitVelocityOverLifetime.limitMultiplier)); } speedLimitByLifeData.AddField("dampen", particleSys.limitVelocityOverLifetime.dampen); switch (particleSys.limitVelocityOverLifetime.space) { case ParticleSystemSimulationSpace.Local: speedLimitByLifeData.AddField("space", 1); break; case ParticleSystemSimulationSpace.World: speedLimitByLifeData.AddField("space", 2); break; case ParticleSystemSimulationSpace.Custom: break; default: break; } #if UNITY_2017_1_OR_NEWER speedLimitByLifeData.AddField("drag", ParseMinMaxCurve(particleSys.limitVelocityOverLifetime.drag)); speedLimitByLifeData.AddField("dragMultiplyBySize", particleSys.limitVelocityOverLifetime.multiplyDragByParticleSize); speedLimitByLifeData.AddField("dragMultiplyBySpeed", particleSys.limitVelocityOverLifetime.multiplyDragByParticleVelocity); #endif } if (particleSys.colorOverLifetime.enabled) { JSONObject colorOverLifetime = new JSONObject(JSONObject.Type.OBJECT); JSONObject colorOverLifetimeData = new JSONObject(JSONObject.Type.OBJECT); data.AddField("colorByLife", colorOverLifetimeData); colorOverLifetimeData.AddField("gColor", ParseMinMaxGradient(particleSys.colorOverLifetime.color)); } if (particleSys.shape.enabled) { JSONObject shapeData = new JSONObject(JSONObject.Type.OBJECT); var haveShape = true; if (particleSys.shape.shapeType == ParticleSystemShapeType.Cone || particleSys.shape.shapeType == ParticleSystemShapeType.ConeVolume || particleSys.shape.shapeType == ParticleSystemShapeType.ConeVolumeShell || particleSys.shape.shapeType == ParticleSystemShapeType.ConeShell) { shapeData.AddField("shape", ParseConeShape(particleSys.shape)); } else if (particleSys.shape.shapeType == ParticleSystemShapeType.Sphere || particleSys.shape.shapeType == ParticleSystemShapeType.SphereShell) { shapeData.AddField("shape", ParseSphereShape(particleSys.shape)); } else if (particleSys.shape.shapeType == ParticleSystemShapeType.Circle || particleSys.shape.shapeType == ParticleSystemShapeType.CircleEdge) { shapeData.AddField("shape", ParseCircleShape(particleSys.shape)); } else if (particleSys.shape.shapeType == ParticleSystemShapeType.Box || particleSys.shape.shapeType == ParticleSystemShapeType.BoxEdge || particleSys.shape.shapeType == ParticleSystemShapeType.BoxShell) { shapeData.AddField("shape", ParseBox(particleSys.shape)); } else if (particleSys.shape.shapeType == ParticleSystemShapeType.Hemisphere || particleSys.shape.shapeType == ParticleSystemShapeType.HemisphereShell) { shapeData.AddField("shape", ParseHemisphere(particleSys.shape)); } // else if (particleSys.shape.shapeType == ParticleSystemShapeType.SingleSidedEdge) { // shapeData.AddField("shape", ParseSingleSidedEdge(particleSys.shape)); // } else { var parentChain = go.name; var parent = go.transform.parent; while (parent) { parentChain += " -> " + parent.gameObject.name; parent = parent.parent; } Debug.LogError("unSupport shape (" + particleSys.shape.shapeType.ToString() + ") at: " + parentChain); haveShape = false; } if (haveShape) { data.AddField("emitterShape", shapeData); } } if (particleSys.textureSheetAnimation.enabled) { JSONObject textureSheetAnimationData = new JSONObject(JSONObject.Type.OBJECT); data.AddField("textureSheetAnimation", textureSheetAnimationData); int mode = 1; #if UNITY_2017_1_OR_NEWER mode = 1; switch (particleSys.textureSheetAnimation.mode) { case ParticleSystemAnimationMode.Grid: mode = 1; break; case ParticleSystemAnimationMode.Sprites: mode = 2; break; default: break; } textureSheetAnimationData.AddField("mode", mode); #endif JSONObject vec2 = new JSONObject(JSONObject.Type.ARRAY); vec2.Add(particleSys.textureSheetAnimation.numTilesX); vec2.Add(particleSys.textureSheetAnimation.numTilesY); textureSheetAnimationData.AddField("tiles", vec2); mode = 1; switch (particleSys.textureSheetAnimation.animation) { case ParticleSystemAnimationType.WholeSheet: mode = 1; break; case ParticleSystemAnimationType.SingleRow: mode = 2; break; default: break; } textureSheetAnimationData.AddField("animationType", mode); textureSheetAnimationData.AddField("randomRow", particleSys.textureSheetAnimation.useRandomRow); textureSheetAnimationData.AddField("row", particleSys.textureSheetAnimation.rowIndex); //mode = 1; //switch (particleSys.textureSheetAnimation.timeMode) //{ // case ParticleSystemAnimationTimeMode.Lifetime: // mode = 1; // break; // case ParticleSystemAnimationTimeMode.Speed: // mode = 2; // break; // case ParticleSystemAnimationTimeMode.FPS: // mode = 3; // break; // default: // break; //} textureSheetAnimationData.AddField("timeMode", 1); if (mode == 1) { textureSheetAnimationData.AddField("frameOverTime", ParseMinMaxCurve(particleSys.textureSheetAnimation.frameOverTime, particleSys.textureSheetAnimation.numTilesX * particleSys.textureSheetAnimation.numTilesY)); } else { textureSheetAnimationData.AddField("frameOverTime", ParseMinMaxCurve(particleSys.textureSheetAnimation.frameOverTime, particleSys.textureSheetAnimation.numTilesX)); } textureSheetAnimationData.AddField("startFrame", ParseMinMaxCurve(particleSys.textureSheetAnimation.startFrame)); textureSheetAnimationData.AddField("cycles", particleSys.textureSheetAnimation.cycleCount); mode = 0; var a = particleSys.textureSheetAnimation.uvChannelMask; var b = a & UVChannelFlags.UV0; if ((a & UVChannelFlags.UV0) != 0) { mode += 1; } if ((a & UVChannelFlags.UV1) != 0) { mode += 2; } if ((a & UVChannelFlags.UV2) != 0) { mode += 3; } if ((a & UVChannelFlags.UV3) != 0) { mode += 4; } textureSheetAnimationData.AddField("affectedUVChannels", mode); } if (particleSys.subEmitters.enabled) { JSONObject subEmittersData = new JSONObject(JSONObject.Type.ARRAY); data.AddField("subEmitters", subEmittersData); int count = particleSys.subEmitters.subEmittersCount; for (int i = 0; i < count; i++) { ParticleSystemSubEmitterProperties properties = particleSys.subEmitters.GetSubEmitterProperties(i); ParticleSystemSubEmitterType type = particleSys.subEmitters.GetSubEmitterType(i); JSONObject res = new JSONObject(JSONObject.Type.OBJECT); int typeNum = 0; switch (type) { case ParticleSystemSubEmitterType.Birth: typeNum = 0; break; case ParticleSystemSubEmitterType.Collision: typeNum = 1; break; case ParticleSystemSubEmitterType.Death: typeNum = 2; break; default: break; } res.AddField("type", typeNum); int propertiesNum = 0; switch (properties) { case ParticleSystemSubEmitterProperties.InheritNothing: propertiesNum = 0; break; case ParticleSystemSubEmitterProperties.InheritEverything: propertiesNum = 1; break; case ParticleSystemSubEmitterProperties.InheritColor: propertiesNum = 2; break; case ParticleSystemSubEmitterProperties.InheritSize: propertiesNum = 3; break; case ParticleSystemSubEmitterProperties.InheritRotation: propertiesNum = 4; break; default: break; } res.AddField("properties", propertiesNum); subEmittersData.Add(res); } } return(json); }
private byte[] WriteMeshFile(ref JSONObject metadata) { MemoryStream fileStream = new MemoryStream(); string meshName = mesh.name; WXMeshVertexLayout vertexLayout = new WXMeshVertexLayout(mesh); ushort subMeshCount = (ushort)mesh.subMeshCount; long vertexStart = 0L; long vertexLength = 0L; long indiceStart = 0L; long indiceLength = 0L; vertexStart = fileStream.Position; Vector3 vertexPositionMax = new Vector3(0, 0, 0); for (int j = 0; j < mesh.vertexCount; j++) { Vector3 vector = mesh.vertices[j]; wxFileUtil.WriteData(fileStream, vector.x * -1f, vector.y, vector.z); vertexPositionMax.Set(vertexPositionMax.x + vector.x * -1f, vertexPositionMax.y + vector.y, vertexPositionMax.z + vector.z); if (vertexLayout.NORMAL) { Vector3 vector2 = mesh.normals[j]; wxFileUtil.WriteData(fileStream, vector2.x * -1f, vector2.y, vector2.z); } if (vertexLayout.COLOR) { Color color = mesh.colors[j]; wxFileUtil.WriteData(fileStream, color.r, color.g, color.b, color.a); } if (vertexLayout.UV) { Vector2 vector3 = mesh.uv[j]; wxFileUtil.WriteData(fileStream, vector3.x, vector3.y * -1f + 1f); } if (vertexLayout.UV1) { Vector2 vector4 = mesh.uv2[j]; wxFileUtil.WriteData(fileStream, vector4.x, vector4.y * -1f + 1f); } if (vertexLayout.TANGENT) { Vector4 vector5 = mesh.tangents[j]; wxFileUtil.WriteData(fileStream, vector5.x * -1f, vector5.y, vector5.z, vector5.w); } } vertexLength = fileStream.Position - vertexStart; indiceStart = fileStream.Position; int[] triangles = mesh.triangles; for (int j = 0; j < triangles.Length; j++) { wxFileUtil.WriteData(fileStream, (ushort)triangles[j]); } indiceLength = fileStream.Position - indiceStart; fileStream.Close(); vertexPositionMax.Set(vertexPositionMax.x / mesh.vertices.Length, vertexPositionMax.y / mesh.vertices.Length, vertexPositionMax.z / mesh.vertices.Length); float capsuleRadius = CalCapsuleRadius(vertexPositionMax, mesh.vertices); JSONObject capsule = new JSONObject(JSONObject.Type.OBJECT); capsule.AddField("x", vertexPositionMax.x); capsule.AddField("y", vertexPositionMax.y); capsule.AddField("z", vertexPositionMax.z); capsule.AddField("radius", capsuleRadius); metadata.AddField("indiceFormat", 1); // BIT16 = 1,BIT32 = 2 metadata.AddField("vertexLayout", vertexLayout.GetLayoutString()); //"POSITION,NORMAL,COLOR,UV,BLENDWEIGHT,BLENDINDICES,TANGENT", metadata.AddField("vertexStart", 0); metadata.AddField("vertexLength", vertexLength); metadata.AddField("indiceStart", vertexLength); // indice的偏移量 metadata.AddField("indiceLength", indiceLength); // indice的长度 metadata.AddField("capsule", capsule); metadata.AddField("version", 1); JSONObject subMeshs = new JSONObject(JSONObject.Type.ARRAY); #if !UNITY_2017_1_OR_NEWER int indexStart = 0; #endif for (int i = 0; i < subMeshCount; i++) { JSONObject subMeshObj = new JSONObject(JSONObject.Type.OBJECT); #if UNITY_2017_1_OR_NEWER subMeshObj.AddField("start", mesh.GetIndexStart(i)); subMeshObj.AddField("length", mesh.GetIndexCount(i)); #else subMeshObj.AddField("start", indexStart); subMeshObj.AddField("length", mesh.GetIndices(i).Length); indexStart += mesh.GetIndices(i).Length; #endif subMeshs.Add(subMeshObj); } metadata.AddField("subMeshs", subMeshs); JSONObject boundBox = new JSONObject(JSONObject.Type.OBJECT); JSONObject boundBoxCenter = new JSONObject(JSONObject.Type.ARRAY); boundBoxCenter.Add(mesh.bounds.center.x); boundBoxCenter.Add(mesh.bounds.center.y); boundBoxCenter.Add(mesh.bounds.center.z); JSONObject boundBoxSize = new JSONObject(JSONObject.Type.ARRAY); boundBoxSize.Add(mesh.bounds.size.x); boundBoxSize.Add(mesh.bounds.size.y); boundBoxSize.Add(mesh.bounds.size.z); boundBox.AddField("center", boundBoxCenter); boundBox.AddField("size", boundBoxSize); metadata.AddField("boundBox", boundBox); return(fileStream.ToArray()); }
protected override JSONObject ToJSON(WXHierarchyContext context) { JSONObject json = new JSONObject(JSONObject.Type.OBJECT); JSONObject data = new JSONObject(JSONObject.Type.OBJECT); json.AddField("type", "TrailRenderer"); json.AddField("data", data); data.AddField("active", renderer.enabled); JSONObject materialArray = new JSONObject(JSONObject.Type.ARRAY); Material[] materials = renderer.sharedMaterials; foreach (Material material in materials) { WXMaterial materialConverter = new WXMaterial(material, renderer); string materialPath = materialConverter.Export(context.preset); materialArray.Add(materialPath); context.AddResource(materialPath); } data.AddField("materials", materialArray); ShadowCastingMode mode = renderer.shadowCastingMode; StaticEditorFlags shadowFlags = GameObjectUtility.GetStaticEditorFlags(renderer.gameObject); #if UNITY_2019_2_OR_NEWER if (mode == ShadowCastingMode.Off || (shadowFlags & StaticEditorFlags.ContributeGI) != 0) #else if (mode == ShadowCastingMode.Off || (shadowFlags & StaticEditorFlags.LightmapStatic) != 0) #endif { data.AddField("castShadow", false); } else { data.AddField("castShadow", true); } bool receiveShadow = renderer.receiveShadows; data.AddField("receiveShadow", receiveShadow); int alignmentNum = 0; #if UNITY_2017_1_OR_NEWER LineAlignment alignment = renderer.alignment; switch (alignment) { case LineAlignment.View: alignmentNum = 0; break; #if UNITY_2018_2_OR_NEWER case LineAlignment.TransformZ: alignmentNum = 1; break; #else case LineAlignment.Local: alignmentNum = 1; break; #endif } data.AddField("alignment", alignmentNum); #endif Color startColor = renderer.startColor; data.AddField("startColor", parseColor(startColor)); Color endColor = renderer.endColor; data.AddField("endColor", parseColor(endColor)); float startWidth = renderer.startWidth; data.AddField("startWidth", startWidth); float endWidth = renderer.endWidth; data.AddField("endWidth", endWidth); float time = renderer.time; data.AddField("time", time); LineTextureMode textureMode = renderer.textureMode; int textureModeNum = 0; switch (textureMode) { case LineTextureMode.Stretch: textureModeNum = 0; break; case LineTextureMode.Tile: textureModeNum = 1; break; } data.AddField("textureMode", textureModeNum); data.AddField("numCapVertices", renderer.numCapVertices); data.AddField("numCornerVertices", renderer.numCornerVertices); data.AddField("minVertexDistance", renderer.minVertexDistance); data.AddField("gColor", GetGradientColor(renderer.colorGradient)); data.AddField("widthCurve", GetCurveData(renderer.widthCurve)); data.AddField("widthMultiplier", renderer.widthMultiplier); return(json); }