protected override JSONObject ToJSON(WXHierarchyContext context) { JSONObject json = new JSONObject(JSONObject.Type.OBJECT); JSONObject data = new JSONObject(JSONObject.Type.OBJECT); json.AddField("type", "SkinnedMeshRenderer"); json.AddField("data", data); // Mesh mesh = (renderer.gameObject.GetComponent (typeof(MeshFilter)) as MeshFilter).sharedMesh; // SkinnedMeshRenderer component = renderer.gameObject.GetComponent<SkinnedMeshRenderer>(); data.AddField("active", renderer.enabled); Mesh mesh = renderer.sharedMesh; if (mesh != null) { WXSkinnedMesh meshConverter = new WXSkinnedMesh(mesh, renderer); string meshPath = meshConverter.Export(context.preset); data.AddField("mesh", meshPath); context.AddResource(meshPath); } else { Debug.LogWarning("mesh is null"); } 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); data.AddField("props", GenProps()); int lightmapIndex = renderer.lightmapIndex; JSONObject litmapScaleArr = new JSONObject(JSONObject.Type.ARRAY); data.AddField("lightMapScaleOffset", litmapScaleArr); litmapScaleArr.Add(renderer.lightmapScaleOffset.x); litmapScaleArr.Add(renderer.lightmapScaleOffset.y); litmapScaleArr.Add(renderer.lightmapScaleOffset.z); litmapScaleArr.Add(renderer.lightmapScaleOffset.w); data.AddField("lightMapIndex", lightmapIndex); ShadowCastingMode mode = renderer.shadowCastingMode; if (mode == ShadowCastingMode.Off) { data.AddField("castShadow", false); } else { data.AddField("castShadow", true); } bool receiveShadow = renderer.receiveShadows; data.AddField("receiveShadow", receiveShadow); return(json); }
private static void RegisterUnityProperties() { AddPropertyHandler(typeof(Vector2), (obj, context) => { Vector2 v = (Vector2)obj; if (v == null) { return(null); } JSONObject vec2 = new JSONObject(JSONObject.Type.ARRAY); vec2.Add(v.x); vec2.Add(v.y); return(vec2); }); AddPropertyHandler(typeof(Vector3), (obj, context) => { Vector3 v = (Vector3)obj; if (v == null) { return(null); } JSONObject vec3 = new JSONObject(JSONObject.Type.ARRAY); vec3.Add(v.x); vec3.Add(v.y); vec3.Add(v.z); return(vec3); }); AddPropertyHandler(typeof(Vector4), (obj, context) => { Vector4 v = (Vector4)obj; if (v == null) { return(null); } JSONObject vec4 = new JSONObject(JSONObject.Type.ARRAY); vec4.Add(v.x); vec4.Add(v.y); vec4.Add(v.z); vec4.Add(v.w); return(vec4); }); AddPropertyHandler(typeof(Quaternion), (obj, context) => { Quaternion v = (Quaternion)obj; if (v == null) { return(null); } JSONObject array4 = new JSONObject(JSONObject.Type.ARRAY); array4.Add(v.x); array4.Add(v.y); array4.Add(v.z); array4.Add(v.w); return(array4); }); AddPropertyHandler(typeof(Matrix4x4), (obj, context) => { Matrix4x4 v = (Matrix4x4)obj; if (v == null) { return(null); } JSONObject array16 = new JSONObject(JSONObject.Type.ARRAY); array16.Add(v.m00); array16.Add(v.m01); array16.Add(v.m02); array16.Add(v.m03); array16.Add(v.m10); array16.Add(v.m11); array16.Add(v.m12); array16.Add(v.m13); array16.Add(v.m20); array16.Add(v.m21); array16.Add(v.m22); array16.Add(v.m23); array16.Add(v.m30); array16.Add(v.m31); array16.Add(v.m32); array16.Add(v.m33); return(array16); }); AddPropertyHandler(typeof(Color), (obj, context) => { Color c = (Color)obj; if (c == null) { return(null); } JSONObject vec4 = new JSONObject(JSONObject.Type.ARRAY); vec4.Add((int)(c.r * 255)); vec4.Add((int)(c.g * 255)); vec4.Add((int)(c.b * 255)); vec4.Add((int)(c.a * 255)); return(vec4); }); AddPropertyHandler(typeof(TextAsset), (obj, context) => { TextAsset t = (TextAsset)obj; if (!t) { return(null); } string path = AssetDatabase.GetAssetPath(t); // string copyToPath = Path.Combine(WXResourceStore.storagePath, path); // Debug.Log("WXResourceStore.storagePath:" + WXResourceStore.storagePath); // Debug.Log("path:" + path); // Debug.Log("copyToPath:" + copyToPath); // Regex regex = new Regex(".txt$"); // copyToPath = regex.Replace(copyToPath, ".json"); // if (!Directory.Exists(WXResourceStore.storagePath + "Assets/")) { // Directory.CreateDirectory(WXResourceStore.storagePath + "Assets/"); // } // FileStream fs = new FileStream(copyToPath, FileMode.Create, FileAccess.Write); // wxFileUtil.WriteData(fs, JsonConvert.SerializeObject(new { text = t.text })); // fs.Close(); JSONObject json = new JSONObject(JSONObject.Type.OBJECT); JSONObject data = new JSONObject(JSONObject.Type.OBJECT); // Debug.Log("JsonConvert.SerializeObject(t.text): " + JsonConvert.SerializeObject(t.text)); string text = JsonConvert.SerializeObject(t.text); // 去掉首尾双引号 text = text.Remove(0, 1); text = text.Substring(0, text.Length - 1); data.AddField("text", text); data.AddField("path", path); json.AddField("type", "UnityEngine.TextAsset".EscapeNamespaceSimple()); json.AddField("value", data); return(json); }); AddPropertyHandler(typeof(Material), (obj, context) => { Material material = (Material)obj; if (material == null) { return(null); } WXMaterial materialConverter = new WXMaterial(material, null); string materialPath = materialConverter.Export(context.preset); context.AddResource(materialPath); JSONObject json = new JSONObject(JSONObject.Type.OBJECT); JSONObject data = new JSONObject(JSONObject.Type.OBJECT); json.AddField("type", "UnityEngine.Material".EscapeNamespaceSimple()); json.AddField("value", data); data.AddField("path", materialPath); return(json); }); AddPropertyHandler(typeof(List <>), (obj, context) => { IEnumerable list = (IEnumerable)obj; if (list == null) { return(null); } JSONObject result = new JSONObject(JSONObject.Type.ARRAY); var enumerator = ((IEnumerable)list).GetEnumerator(); while (enumerator.MoveNext()) { object itemObj = enumerator.Current; if (itemObj == null) { continue; } if (itemObj.GetType() == typeof(List <>)) { throw new Exception("List不支持嵌套"); } else { Type type = itemObj.GetType(); if (type.IsSubclassOf(typeof(UnityEngine.Component)) || type == typeof(UnityEngine.GameObject)) { var o = (UnityEngine.Object)itemObj; GameObject go = null; if (o == null) { continue; } if (type.IsSubclassOf(typeof(UnityEngine.Component))) { go = ((Component)o).gameObject; } else if (type == typeof(UnityEngine.GameObject)) { go = (GameObject)o; } var path = AssetDatabase.GetAssetPath(o); // Prefab? if (go.transform.IsChildOf(context.Root.transform) || path == "") { if (!propertiesHandlerDictionary.ContainsKey(type) && !type.IsArray && (!type.IsGenericType || type.GetGenericTypeDefinition() != typeof(List <>)) && type.IsSerializable) { var sobj = new JSONObject(JSONObject.Type.OBJECT); result.Add(sobj); SerializableHandler(type, sobj, itemObj, context); } else if (type != typeof(System.Object) && propertiesHandlerDictionary.ContainsKey(type)) { var res = propertiesHandlerDictionary[type](itemObj, context); result.Add(res); } continue; } if (!WXMonoBehaviourExportHelper.exportedResourcesSet.Contains(go)) { WXMonoBehaviourExportHelper.exportedResourcesSet.Add(go); WXPrefab converter = new WXPrefab(go, path); string prefabPath = converter.Export(ExportPreset.GetExportPreset("prefab")); context.AddResource(prefabPath); } var prefabInfo = new JSONObject(JSONObject.Type.OBJECT); prefabInfo.AddField("type", type.FullName.EscapeNamespaceSimple()); prefabInfo.AddField("path", path); var innerData = new JSONObject(JSONObject.Type.OBJECT); innerData.AddField("type", "UnityPrefabWrapper"); innerData.AddField("value", prefabInfo); // data.AddField(field.Name, innerData); result.Add(innerData); } else if (!propertiesHandlerDictionary.ContainsKey(type) && !type.IsArray && (!type.IsGenericType || type.GetGenericTypeDefinition() != typeof(List <>)) && type.IsSerializable) { var sobj = new JSONObject(JSONObject.Type.OBJECT); result.Add(sobj); SerializableHandler(type, sobj, itemObj, context); } else if (type != typeof(System.Object) && propertiesHandlerDictionary.ContainsKey(type)) { var res = propertiesHandlerDictionary[type](itemObj, context); result.Add(res); } } } return(result); }); // disgusting code logic :( // refactor should be needed AddPropertyHandler(typeof(MonoBehaviour), (obj, context) => { var m = (MonoBehaviour)obj; if (!m) { return(null); } if (ExportLogger.LOGGING) { ExportLogger.AddLog(new ExportLogger.Log(ExportLogger.Log.Type.Property, "Object: " + obj + "\nType: " + obj.GetType())); } var go = m.gameObject; JSONObject innerData = new JSONObject(JSONObject.Type.OBJECT); var path = AssetDatabase.GetAssetPath(go); // Prefab? if (go.transform.IsChildOf(context.Root.transform) || path == "") { var typeName = m.GetType().FullName; var escapedTypeName = WXMonoBehaviourExportHelper.EscapeNamespace(typeName); innerData.AddField("type", escapedTypeName); innerData.AddField("value", context.AddComponentInProperty(new WXEngineMonoBehaviour(m), (Component)obj)); return(innerData); } if (!WXMonoBehaviourExportHelper.exportedResourcesSet.Contains(go)) { WXMonoBehaviourExportHelper.exportedResourcesSet.Add(go); WXPrefab converter = new WXPrefab(go, path); string prefabPath = converter.Export(ExportPreset.GetExportPreset("prefab")); context.AddResource(prefabPath); } var prefabInfo = new JSONObject(JSONObject.Type.OBJECT); { var typeName = m ? m.GetType().FullName : "UnityEngine.GameObject"; var escapedTypeName = WXMonoBehaviourExportHelper.EscapeNamespace(typeName); prefabInfo.AddField("type", escapedTypeName); } prefabInfo.AddField("path", path); innerData.AddField("type", "UnityPrefabWrapper"); innerData.AddField("value", prefabInfo); return(innerData); }); AddPropertyHandler(typeof(Component), (obj, context) => { Component c = (Component)obj; if (!c) { return(null); } if (ExportLogger.LOGGING) { ExportLogger.AddLog(new ExportLogger.Log(ExportLogger.Log.Type.Property, "Object: " + obj + "\nType: " + obj.GetType())); } JSONObject innerData = new JSONObject(JSONObject.Type.OBJECT); var escapedTypeName = WXMonoBehaviourExportHelper.EscapeNamespace(c.GetType().FullName); innerData.AddField("type", escapedTypeName); if (c is Transform) { innerData = GetPrefabOnSerializedField(context, c.gameObject, innerData, false); } // 下面是adaptor独有的类才需要单独写 // Physics //else if (c is BoxCollider) { // innerData.AddField("value", context.AddComponent(new WXBoxCollider((BoxCollider)c), (BoxCollider)c)); //} else if (c is SphereCollider) { // innerData.AddField("value", context.AddComponent(new WXSphereCollider((SphereCollider)c), (SphereCollider)c)); //} else if (c is CapsuleCollider) { // innerData.AddField("value", context.AddComponent(new WXCapsuleCollider((CapsuleCollider)c), (CapsuleCollider)c)); //} else if (c is MeshCollider) { // innerData.AddField("value", context.AddComponent(new WXMeshCollider((MeshCollider)c), (MeshCollider)c)); //} else if (c is Rigidbody) { // innerData.AddField("value", context.AddComponent(new WXRigidbody((Rigidbody)c), (Rigidbody)c)); //} else if (c is AudioSource) { innerData.AddField("value", context.AddComponentInProperty(new WXEngineAudioSource((AudioSource)c), (AudioSource)c)); } // 有ref的类 else { // if (context.componentDictionary.ContainsKey(c)) { innerData.AddField("value", context.AddComponentInProperty(new WXUnityComponent(c), c)); // } } return(innerData); }); AddPropertyHandler(typeof(GameObject), (obj, context) => { var go = (GameObject)obj; if (!go) { return(null); } if (ExportLogger.LOGGING) { ExportLogger.AddLog(new ExportLogger.Log(ExportLogger.Log.Type.Property, "Object: " + obj + "\nType: " + obj.GetType())); } JSONObject innerData = new JSONObject(JSONObject.Type.OBJECT); return(GetPrefabOnSerializedField(context, go, innerData)); }); }
protected override JSONObject ToJSON(WXHierarchyContext context) { JSONObject json = new JSONObject(JSONObject.Type.OBJECT); JSONObject data = new JSONObject(JSONObject.Type.OBJECT); json.AddField("type", "LineRenderer"); json.AddField("data", data); 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 (mode == ShadowCastingMode.Off || (shadowFlags & StaticEditorFlags.LightmapStatic) != 0) { 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); 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); int positionCount = 0; #if UNITY_2017_1_OR_NEWER positionCount = renderer.positionCount; #else positionCount = renderer.numPositions; #endif Vector3[] positionsVec = new Vector3[positionCount]; renderer.GetPositions(positionsVec); JSONObject jSONObject = new JSONObject(JSONObject.Type.ARRAY); for (int i = 0; i < positionCount; i++) { JSONObject vec = new JSONObject(JSONObject.Type.ARRAY); vec.Add(positionsVec[i].x * -1f); vec.Add(positionsVec[i].y); vec.Add(positionsVec[i].z); jSONObject.Add(vec); } data.AddField("positions", jSONObject); data.AddField("numCapVertices", renderer.numCapVertices); data.AddField("numCornerVertices", renderer.numCornerVertices); #if UNITY_2017_1_OR_NEWER data.AddField("loop", renderer.loop); #endif data.AddField("useWorldSpace", renderer.useWorldSpace); data.AddField("gColor", GetGradientColor(renderer.colorGradient)); data.AddField("widthCurve", GetCurveData(renderer.widthCurve)); data.AddField("widthMultiplier", renderer.widthMultiplier); return(json); }
protected override JSONObject ToJSON(WXHierarchyContext context) { 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(0, "粒子组件没有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); }
protected override JSONObject ToJSON(WXHierarchyContext context) { JSONObject json = new JSONObject(JSONObject.Type.OBJECT); JSONObject data = new JSONObject(JSONObject.Type.OBJECT); json.AddField("type", "MeshRenderer"); json.AddField("data", data); Mesh mesh = (renderer.gameObject.GetComponent(typeof(MeshFilter)) as MeshFilter).sharedMesh; if (mesh != null) { WXMesh meshConverter = new WXMesh(mesh); string meshPath = meshConverter.Export(context.preset); data.AddField("mesh", meshPath); context.AddResource(meshPath); } else { Debug.LogError(string.Format("{0} mesh is null", renderer.name)); } JSONObject materialArray = new JSONObject(JSONObject.Type.ARRAY); Material[] materials = renderer.sharedMaterials; foreach (Material material in materials) { if (material != null) { WXMaterial materialConverter = new WXMaterial(material, renderer); string materialPath = materialConverter.Export(context.preset); materialArray.Add(materialPath); context.AddResource(materialPath); } } data.AddField("materials", materialArray); int lightmapIndex = renderer.lightmapIndex; JSONObject litmapScaleArr = new JSONObject(JSONObject.Type.ARRAY); data.AddField("lightMapScaleOffset", litmapScaleArr); litmapScaleArr.Add(renderer.lightmapScaleOffset.x); litmapScaleArr.Add(renderer.lightmapScaleOffset.y); litmapScaleArr.Add(renderer.lightmapScaleOffset.z); litmapScaleArr.Add(renderer.lightmapScaleOffset.w); data.AddField("lightMapIndex", lightmapIndex); ShadowCastingMode mode = renderer.shadowCastingMode; StaticEditorFlags shadowFlags = GameObjectUtility.GetStaticEditorFlags(renderer.gameObject); if (mode == ShadowCastingMode.Off || (shadowFlags & StaticEditorFlags.LightmapStatic) != 0) { data.AddField("castShadow", false); } else { data.AddField("castShadow", true); } bool receiveShadow = renderer.receiveShadows; data.AddField("receiveShadow", receiveShadow); return(json); }
protected override JSONObject ToJSON(WXHierarchyContext context) { JSONObject json = new JSONObject(JSONObject.Type.OBJECT); JSONObject data = new JSONObject(JSONObject.Type.OBJECT); json.AddField("type", "MeshRenderer"); json.AddField("data", data); data.AddField("active", renderer.enabled); JSONObject materialArray = new JSONObject(JSONObject.Type.ARRAY); Material[] materials = renderer.sharedMaterials; int materialCount = 0; foreach (Material material in materials) { if (material != null) { WXMaterial materialConverter = new WXMaterial(material, renderer); string materialPath = materialConverter.Export(context.preset); materialArray.Add(materialPath); context.AddResource(materialPath); materialCount++; } } data.AddField("materials", materialArray); MeshFilter meshFilter = renderer.gameObject.GetComponent <MeshFilter> (); if (meshFilter != null && meshFilter.sharedMesh != null) { Mesh mesh = meshFilter.sharedMesh; WXMesh meshConverter = new WXMesh(mesh, materialCount); string meshPath = meshConverter.Export(context.preset); data.AddField("mesh", meshPath); context.AddResource(meshPath); } else { ErrorUtil.ExportErrorReporter.create() .setGameObject(renderer.gameObject) .setHierarchyContext(context) .error(ErrorUtil.ErrorCode.MeshRenderer_MeshNotFound, "Mesh资源转换失败,没法拿到对应的MeshFilter或者它上面的mesh"); } int lightmapIndex = renderer.lightmapIndex; JSONObject litmapScaleArr = new JSONObject(JSONObject.Type.ARRAY); data.AddField("lightMapScaleOffset", litmapScaleArr); litmapScaleArr.Add(renderer.lightmapScaleOffset.x); litmapScaleArr.Add(renderer.lightmapScaleOffset.y); litmapScaleArr.Add(renderer.lightmapScaleOffset.z); litmapScaleArr.Add(renderer.lightmapScaleOffset.w); data.AddField("lightMapIndex", lightmapIndex); 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); return(json); }
private static void RegisterUnityProperties() { AddTypePropertyHandler(typeof(Vector2), (obj, context, requireList) => { Vector2 v = (Vector2)obj; if (v == null) { return(null); } JSONObject vec2 = new JSONObject(JSONObject.Type.ARRAY); vec2.Add(v.x); vec2.Add(v.y); return(vec2); }); AddTypePropertyHandler(typeof(Vector3), (obj, context, requireList) => { Vector3 v = (Vector3)obj; if (v == null) { return(null); } JSONObject vec3 = new JSONObject(JSONObject.Type.ARRAY); vec3.Add(v.x); vec3.Add(v.y); vec3.Add(v.z); return(vec3); }); AddTypePropertyHandler(typeof(Vector4), (obj, context, requireList) => { Vector4 v = (Vector4)obj; if (v == null) { return(null); } JSONObject vec4 = new JSONObject(JSONObject.Type.ARRAY); vec4.Add(v.x); vec4.Add(v.y); vec4.Add(v.z); vec4.Add(v.w); return(vec4); }); AddTypePropertyHandler(typeof(Quaternion), (obj, context, requireList) => { Quaternion v = (Quaternion)obj; if (v == null) { return(null); } JSONObject array4 = new JSONObject(JSONObject.Type.ARRAY); array4.Add(v.x); array4.Add(v.y); array4.Add(v.z); array4.Add(v.w); return(array4); }); AddTypePropertyHandler(typeof(Matrix4x4), (obj, context, requireList) => { Matrix4x4 v = (Matrix4x4)obj; if (v == null) { return(null); } JSONObject array16 = new JSONObject(JSONObject.Type.ARRAY); array16.Add(v.m00); array16.Add(v.m01); array16.Add(v.m02); array16.Add(v.m03); array16.Add(v.m10); array16.Add(v.m11); array16.Add(v.m12); array16.Add(v.m13); array16.Add(v.m20); array16.Add(v.m21); array16.Add(v.m22); array16.Add(v.m23); array16.Add(v.m30); array16.Add(v.m31); array16.Add(v.m32); array16.Add(v.m33); return(array16); }); AddTypePropertyHandler(typeof(Color), (obj, context, requireList) => { Color c = (Color)obj; if (c == null) { return(null); } JSONObject vec4 = new JSONObject(JSONObject.Type.ARRAY); vec4.Add((int)(c.r * 255)); vec4.Add((int)(c.g * 255)); vec4.Add((int)(c.b * 255)); vec4.Add((int)(c.a * 255)); return(vec4); }); AddTypePropertyHandler(typeof(TextAsset), (obj, context, requireList) => { TextAsset t = (TextAsset)obj; if (!t) { return(null); } string path = AssetDatabase.GetAssetPath(t); // string copyToPath = Path.Combine(WXResourceStore.storagePath, path); // Debug.Log("WXResourceStore.storagePath:" + WXResourceStore.storagePath); // Debug.Log("path:" + path); // Debug.Log("copyToPath:" + copyToPath); // Regex regex = new Regex(".txt$"); // copyToPath = regex.Replace(copyToPath, ".json"); // if (!Directory.Exists(WXResourceStore.storagePath + "Assets/")) { // Directory.CreateDirectory(WXResourceStore.storagePath + "Assets/"); // } // FileStream fs = new FileStream(copyToPath, FileMode.Create, FileAccess.Write); // wxFileUtil.WriteData(fs, JsonConvert.SerializeObject(new { text = t.text })); // fs.Close(); JSONObject json = new JSONObject(JSONObject.Type.OBJECT); JSONObject data = new JSONObject(JSONObject.Type.OBJECT); // Debug.Log("JsonConvert.SerializeObject(t.text): " + JsonConvert.SerializeObject(t.text)); string text = t.text.Replace("\r\n", "\\n").Replace("\\", "\\\\").Replace("\"", "\\\""); data.AddField("text", text); data.AddField("path", path); json.AddField("type", "UnityEngine.TextAsset".EscapeNamespaceSimple()); json.AddField("value", data); return(json); }); AddTypePropertyHandler(typeof(Material), (obj, context, requireList) => { Material material = (Material)obj; if (material == null) { return(null); } WXMaterial materialConverter = new WXMaterial(material, null); string materialPath = materialConverter.Export(context.preset); context.AddResource(materialPath); JSONObject json = new JSONObject(JSONObject.Type.OBJECT); JSONObject data = new JSONObject(JSONObject.Type.OBJECT); json.AddField("type", "UnityEngine.Material".EscapeNamespaceSimple()); json.AddField("value", data); data.AddField("path", materialPath); return(json); }); AddTypePropertyHandler(typeof(UnityEngine.LayerMask), (obj, context, requireList) => { LayerMask mask = (LayerMask)obj; return(JSONObject.Create(mask.value)); }); AddTypePropertyHandler(typeof(List <>), (obj, context, requireList) => { IEnumerable list = (IEnumerable)obj; if (list == null) { return(null); } JSONObject result = new JSONObject(JSONObject.Type.ARRAY); var enumerator = ((IEnumerable)list).GetEnumerator(); while (enumerator.MoveNext()) { object itemObj = enumerator.Current; if (itemObj == null) { continue; } if (itemObj.GetType() == typeof(List <>)) { throw new Exception("不支持嵌套List"); } else { Type type = itemObj.GetType(); JSONObject itemResult = innerHandleField(type, itemObj, context, requireList); if (itemResult != null) { result.Add(itemResult); } } } return(result); }); AddTypePropertyHandler(typeof(PuertsBeefBallSDK.RemoteResource), (obj, context, requireList) => { var m = (PuertsBeefBallSDK.RemoteResource)obj; return(JSONObject.CreateStringObject(m.resourcePath)); }); // disgusting code logic :( // refactor should be needed AddTypePropertyHandler(typeof(PuertsBeefBallBehaviour), (obj, context, requireList) => { var m = (PuertsBeefBallBehaviour)obj; if (!m) { return(null); } JSONObject innerData = new JSONObject(JSONObject.Type.OBJECT); var escapedTypeName = WXMonoBehaviourExportHelper.EscapeNamespace(m.GetType().FullName); innerData.AddField("type", escapedTypeName); innerData.AddField("value", context.AddComponentInProperty(new PuertsBeefBallBehaviourConverter(m), (Component)obj)); return(innerData); }); AddTypePropertyHandler(typeof(Component), (obj, context, requireList) => { Component c = (Component)obj; if (!c) { return(null); } JSONObject innerData = new JSONObject(JSONObject.Type.OBJECT); var escapedTypeName = WXMonoBehaviourExportHelper.EscapeNamespace(c.GetType().FullName); innerData.AddField("type", escapedTypeName); innerData.AddField("value", context.AddComponentInProperty(new WXUnityComponent(c), c)); return(innerData); }); // 在前面condition逻辑里,理论上已经把所有可能为prefab的逻辑走完 AddTypePropertyHandler(typeof(GameObject), (obj, context, requireList) => { throw new Exception("不支持节点属性指向GameObject,请改为指向Transform或是具体逻辑组件"); // var go = (GameObject)obj; // if (!go) return null; // JSONObject innerData = new JSONObject(JSONObject.Type.OBJECT); // return GetPrefabOnSerializedField(context, go, innerData); }); }
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); }