protected override JSONObject ToJSON(WXHierarchyContext context) { JSONObject json = new JSONObject(JSONObject.Type.OBJECT); JSONObject data = new JSONObject(JSONObject.Type.OBJECT); json.AddField("type", getTypeName()); json.AddField("data", data); data.AddField("active", true); // if (this.collider != null) { data.AddField("isTrigger", this.isTrigger); if (material != null) { WXPhysicsMaterial materialConverter = new WXPhysicsMaterial(material); string materialPath = materialConverter.Export(context.preset); if (materialPath != null && materialPath != "") { data.AddField("material", materialPath); context.AddResource(materialPath); } } JSONObject center = new JSONObject(JSONObject.Type.ARRAY); center.Add(-this.center.x); center.Add(this.center.y); center.Add(this.center.z); data.AddField("center", center); data.AddField("radius", this.radius); } 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", getTypeName()); json.AddField("data", data); JSONObject res_paths_json = new JSONObject(JSONObject.Type.ARRAY); data.AddField("resources", res_paths_json); foreach (Object file in collection_.ResourceFiles) { if (file != null) { string file_path = AssetDatabase.GetAssetPath(file.GetInstanceID()); WXRawResource resourceConverter = new WXRawResource(file_path); string ret_path = resourceConverter.Export(context.preset); if (ret_path != "") { res_paths_json.Add(ret_path); context.AddResource(ret_path); } } } return(json); }
public string getStateSprite(WXHierarchyContext context, Sprite uiSprite) { string uuid = WXUGUISpriteFrame.getSprite(uiSprite, context.preset); context.AddResource(uuid); return(uuid); }
public string getStateSprite(WXHierarchyContext context, UISprite uiSprite, string spriteName) { string uuid = WXSpriteFrame.getSprite(uiSprite.atlas as UIAtlas, spriteName, context.preset); context.AddResource(uuid); return(uuid); }
protected override JSONObject ToJSON(WXHierarchyContext context) { JSONObject json = new JSONObject(JSONObject.Type.OBJECT); JSONObject data = new JSONObject(JSONObject.Type.OBJECT); json.AddField("type", getTypeName()); json.AddField("data", data); data.AddField("active", true); if (this.collider != null) { data.AddField("convex", this.collider.convex); data.AddField("isTrigger", this.collider.isTrigger); data.AddField("cookingOptions", (int)this.collider.cookingOptions); data.AddField("material", new WXPhysicsMaterial(this.collider.material).ToJSON()); Mesh mesh = this.collider.sharedMesh; if (mesh != null) { WXMesh meshConverter = new WXMesh(mesh); string meshPath = meshConverter.Export(context.preset); data.AddField("mesh", meshPath); context.AddResource(meshPath); } } return(json); }
private static JSONObject GetPrefabOnSerializedField(WXHierarchyContext context, GameObject go, JSONObject innerData, bool isGameObject = true, Component comp = null) { // Prefab? var path = AssetDatabase.GetAssetPath(go); if (go.transform.IsChildOf(context.Root.transform) || path == "") { GetGameObjectReferenceIndex(context, go, ref innerData, isGameObject); 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 = comp ? comp.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); // GetGameObjectReferenceIndex(context, go, ref innerData, isGameObject); // return innerData; }
public string HandleAnimationClip(WXHierarchyContext context, AnimationClip animationClip) { string uid = new WXAnimationClip(animationClip).Export(context.preset); // 因为AnimationClip没走AddFile,这里要手动加dependenices //WXBeefBallExportContext.instance.keys.Add(uid, true); context.AddResource(uid); return(uid); }
protected override JSONObject ToJSON(WXHierarchyContext context) { List <string> linkSprite = new List <string>(); JSONObject child = new JSONObject(JSONObject.Type.ARRAY); JSONObject json = new JSONObject(JSONObject.Type.OBJECT); JSONObject data = new JSONObject(JSONObject.Type.OBJECT); JSONObject layers = new JSONObject(JSONObject.Type.ARRAY); json.AddField("type", getTypeName()); json.AddField("data", data); Avatar avatar = animator.avatar; if ((UnityEngine.Object)avatar != (UnityEngine.Object)null) { AssetImporter importer = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(avatar.GetInstanceID())); ModelImporter mImporter = importer as ModelImporter; if (mImporter && mImporter.optimizeGameObjects) { WXAvatar converter = new WXAvatar(avatar, gameObject); string avatarPath = converter.Export(context.preset); if (avatarPath != null && avatarPath != "") { data.AddField("avatar", avatarPath); context.AddResource(avatarPath); } } } if (gameObject.GetComponent <Animator>().runtimeAnimatorController != null) { //string controllerId = SaveController(gameObject); WXResource controllerConverter = (WXResource)WXResource.getConverter( gameObject.GetComponent <Animator>().runtimeAnimatorController, gameObject ); string animatorControllerPath = controllerConverter.Export(context.preset); data.AddField("controller", animatorControllerPath); context.AddResource(animatorControllerPath); } data.AddField("cullingMode", (uint)animator.cullingMode); return(json); }
protected override JSONObject ToJSON(WXHierarchyContext context) { Texture2D texture2D = (Texture2D)(uiAtlas.spriteMaterial).GetTexture("_MainTex"); if (texture2D != null) { string path = AssetDatabase.GetAssetPath(texture2D.GetInstanceID()); string texturePath = new WXTexture(texture2D).Export(context.preset); context.AddResource(texturePath); for (int i = 0; i < uiAtlas.spriteList.Count; i++) { string spriteframePath = new WXSpriteFrame(uiAtlas.spriteList[i], texturePath, path).Export(context.preset); context.AddResource(spriteframePath); } } JSONObject json = new JSONObject(JSONObject.Type.OBJECT); json.AddField("type", "UIAtlas"); 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", getTypeName()); json.AddField("data", data); if (audio != null && audio.clip != null) { AudioClip clip = audio.clip; // var clipResource = new WXBeefBallAudioClip(clip); // var path = clipResource.Export(); // if (!path.Equals("")) { // context.AddResource(path); // } var path = AssetDatabase.GetAssetPath(clip); //string copyToPath = Path.Combine(WXResourceStore.storagePath, path); path = new WXRawResource(path).Export(context.preset); context.AddResource(path); //string subpath = path; //if (subpath.StartsWith("Assets")) //{ // subpath = path.Substring(6); //} //#if UNITY_EDITOR_WIN //string fromPath = Application.dataPath + "\\" + subpath; //#else //string fromPath = Application.dataPath + "/" + subpath; //#endif //try //{ // wxFileUtil.CopyFile(fromPath, copyToPath); //} //catch (Exception e1) //{ // Debug.Log(e1); //} data.AddField("action", true); data.AddField("_clip", path); data.AddField("_mute", this.audio.mute); data.AddField("_playOnAwake", this.audio.playOnAwake); data.AddField("_loop", this.audio.loop); data.AddField("_volume", this.audio.volume); } return(json); }
protected override JSONObject ToJSON(WXHierarchyContext context) { List <string> linkSprite = new List <string>(); JSONObject child = new JSONObject(JSONObject.Type.ARRAY); JSONObject json = new JSONObject(JSONObject.Type.OBJECT); JSONObject data = new JSONObject(JSONObject.Type.OBJECT); JSONObject layers = new JSONObject(JSONObject.Type.ARRAY); json.AddField("type", getTypeName()); json.AddField("data", data); Avatar avatar = animator.avatar; if ((UnityEngine.Object)avatar != (UnityEngine.Object)null) { WXAvatar converter = new WXAvatar(avatar, gameObject); string avatarPath = converter.Export(context.preset); if (avatarPath != null && avatarPath != "") { data.AddField("avatar", avatarPath); context.AddResource(avatarPath); } } if (gameObject.GetComponent <Animator>().runtimeAnimatorController != null) { //string controllerId = SaveController(gameObject); WXResource controllerConverter = (WXResource)WXResource.getConverter( gameObject.GetComponent <Animator>().runtimeAnimatorController, gameObject ); string animatorControllerPath = controllerConverter.Export(context.preset); data.AddField("controller", animatorControllerPath); context.AddResource(animatorControllerPath); } return(json); }
// handle all Serializable class recursively private static void SerializableHandler(Type _type, JSONObject _data, object value, WXHierarchyContext context, List <string> requireList) { if (value == null || _type == null) { return; } // get [SerializeField] && Public properties var fields = _type.GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).Where(f => !f.IsDefined(typeof(NonSerializedAttribute), true) && !f.IsDefined(typeof(HideInInspector), true) && (f.IsDefined(typeof(SerializeField), true) || f.IsPublic)); Dictionary <string, Type> fieldsDict = new Dictionary <string, Type>(); foreach (var f in fields) { object itemValue = f.GetValue(value); // get non-permitive Serializable object && non-IEnumerable object Type fType = f.FieldType; if (fType == null) { continue; } _data.AddField(f.Name, innerHandleField(fType, itemValue, context, requireList)); fieldsDict.Add(f.Name, fType); } // 为serializable生成一个script PuertsSerializableScriptFile scriptFile = new PuertsSerializableScriptFile( _type.FullName, fieldsDict, new List <string>() ); string scriptPath = new WXEngineScriptResource(scriptFile).Export(context.preset); context.AddResource(scriptPath); requireList.Add(scriptPath); }
protected override JSONObject ToJSON(WXHierarchyContext context) { JSONObject json = new JSONObject(JSONObject.Type.OBJECT); JSONObject data = new JSONObject(JSONObject.Type.OBJECT); json.AddField("type", behaviour.GetType().FullName); json.AddField("data", data); Dictionary <string, Type> bindingFields = new Dictionary <string, Type>(); List <string> bindingMethods = new List <string>(); List <string> requireList = new List <string>(); if (this.behaviour != null) { BindingFlags flags = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public; Type myObjectType = behaviour.GetType(); FieldInfo[] fields = myObjectType.GetFields(flags); // if (behaviour.GetType().Name == typeof(PuertsTest.TankMovement).Name) { // var fieldss = behaviour.GetType().GetFields(BindingFlags.Static | BindingFlags.Public); // Debug.Log(fieldss.Length); // foreach (FieldInfo item in fieldss) { // Debug.Log(item.Name); // } // } foreach (FieldInfo field in fields) { if ( // 排除Action field.FieldType.BaseType != typeof(System.MulticastDelegate) && !field.IsDefined(typeof(NonSerializedAttribute), true) && // 排除hideInInspector !field.IsDefined(typeof(HideInInspector), true) ) { JSONObject result = WXMonoBehaviourPropertiesHandler.HandleField(field, behaviour, context, requireList); if (result != null) { data.AddField(field.Name, result); bindingFields.Add(field.Name, field.FieldType); } } } MethodInfo[] methods = myObjectType.GetMethods(flags); foreach (MethodInfo method in methods) { bindingMethods.Add(method.Name); } } string script = new WXEngineScriptResource( new PuertsSerializableScriptFile( behaviour.GetType().FullName, bindingFields, bindingMethods, behaviour.JSClassName, requireList ) ).Export(context.preset); context.AddResource(script); data.AddField("__uuid", script); data.AddField("active", true); return(json); }
// inner recursion method, thus each if-statement must have @return in the end of the following block. private static void innerHandleProperty(Type type, FieldInfo field, object obj, JSONObject data, WXHierarchyContext context) { if (ExportLogger.LOGGING) { ExportLogger.AddLog(new ExportLogger.Log(ExportLogger.Log.Type.Inner, "Type: " + type + "\nObject: " + obj + "\nJson: " + data)); } if (obj == null || type == null || type == typeof(System.Object) || field.IsDefined(typeof(NonSerializedAttribute)) || field.IsDefined(typeof(HideInInspector))) { return; } if (WXBridge.isNGUIPreset) { Type wxnguiType = WXMonoBehaviourExportHelper.GetWXNGUIComponentType(type); if (wxnguiType != null) { var nativeComp = (Component)field.GetValue(obj); if (nativeComp != null) { var go = nativeComp.gameObject; Debug.Log(nativeComp); var entity = context.MakeEntity(go); // 特殊处理 if (wxnguiType.FullName == "WXEngine.WXTransform2DComponent") { data.AddField(field.Name, context.AddComponentInProperty( (WXComponent)Activator.CreateInstance(wxnguiType, (object)nativeComp.transform), nativeComp.transform )); } else { data.AddField(field.Name, context.AddComponentInProperty( (WXComponent)Activator.CreateInstance(wxnguiType, nativeComp, go, entity), nativeComp )); } } } } if (WXBridge.isUGUIPreset) { Type wxuguiType = WXMonoBehaviourExportHelper.GetWXUGUIComponentType(type); if (wxuguiType != null) { var nativeComp = (Component)field.GetValue(obj); if (nativeComp != null) { var go = nativeComp.gameObject; Debug.Log(nativeComp); var entity = context.MakeEntity(go); // 特殊处理 if (wxuguiType.FullName == "WeChat.WXUGUITransform2DComponent") { data.AddField(field.Name, context.AddComponent( (WXComponent)Activator.CreateInstance(wxuguiType, (object)nativeComp.transform), nativeComp.transform )); } else { data.AddField(field.Name, context.AddComponent( (WXComponent)Activator.CreateInstance(wxuguiType, nativeComp, go, entity), nativeComp )); } } } } if (WXBridge.isUGUIPreset) { Type wxuguiType = WXMonoBehaviourExportHelper.GetWXUGUIComponentType(type); if (wxuguiType != null) { var nativeComp = (Component)field.GetValue(obj); if (nativeComp != null) { var go = nativeComp.gameObject; Debug.Log(nativeComp); var entity = context.MakeEntity(go); // 特殊处理 if (wxuguiType.FullName == "WeChat.WXUGUITransform2DComponent") { data.AddField(field.Name, context.AddComponent( (WXComponent)Activator.CreateInstance(wxuguiType, (object)nativeComp.transform), nativeComp.transform )); } else { data.AddField(field.Name, context.AddComponent( (WXComponent)Activator.CreateInstance(wxuguiType, nativeComp, go, entity), nativeComp )); } } } } if (WXMonoBehaviourExportHelper.IsInBlackList(type)) { return; } if (propertiesHandlerDictionary.ContainsKey(type)) { var res = InvokePropertyHandler(type, field.GetValue(obj), context); if (res) { data.AddField(field.Name, res); } return; } else if (type.IsArray || (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List <>))) { var res = InvokePropertyHandler(typeof(List <>), field.GetValue(obj), context); if (res) { data.AddField(field.Name, res); } return; } else if (type.IsEnum) { var res = JSONObject.Create((int)field.GetValue(obj)); if (res) { data.AddField(field.Name, res); } return; } else if (type.IsSubclassOf(typeof(UnityEngine.Component)) || type == typeof(UnityEngine.GameObject)) { // Prefab or not var o = (UnityEngine.Object)field.GetValue(obj); GameObject go = null; if (o == null) { return; } if (type.IsSubclassOf(typeof(UnityEngine.Component))) { go = ((Component)o).gameObject; } else if (type == typeof(UnityEngine.GameObject)) { go = (GameObject)o; } var path = AssetDatabase.GetAssetPath(o); if (go.transform.IsChildOf(context.Root.transform) || path == "") { if (type.IsSerializable) { var _innerData = new JSONObject(JSONObject.Type.OBJECT); data.AddField(field.Name, _innerData); SerializableHandler(type, _innerData, field.GetValue(obj), context); return; } innerHandleProperty(type.BaseType, field, obj, data, context); return; } 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); return; } else if (type.IsSerializable) { // data of serializable object as a new JSONObject to be added var innerData = new JSONObject(JSONObject.Type.OBJECT); data.AddField(field.Name, innerData); SerializableHandler(type, innerData, field.GetValue(obj), context); return; } innerHandleProperty(type.BaseType, field, obj, data, context); }
protected override JSONObject ToJSON(WXHierarchyContext context) { if (uiSprite != null) { //if (uiSprite.isAnchored) //{ // JSONObject anchorJson = new JSONObject(JSONObject.Type.OBJECT); // anchorJson.AddField("type", "UIWidget"); // JSONObject anchorSubJSON = new JSONObject(JSONObject.Type.OBJECT); // anchorSubJSON.AddField("leftMargin", uiSprite.leftAnchor.absolute); // anchorSubJSON.AddField("rightMargin", uiSprite.rightAnchor.absolute); // anchorSubJSON.AddField("topMargin", uiSprite.topAnchor.absolute); // anchorSubJSON.AddField("bottomMargin", uiSprite.bottomAnchor.absolute); // anchorJson.AddField("data", anchorSubJSON); //} JSONObject json = new JSONObject(JSONObject.Type.OBJECT); json.AddField("type", "UISprite"); JSONObject subJSON = new JSONObject(JSONObject.Type.OBJECT); JSONObject color = new JSONObject(JSONObject.Type.ARRAY); color.Add(255f * uiSprite.color.r); color.Add(255f * uiSprite.color.g); color.Add(255f * uiSprite.color.b); color.Add(255f * uiSprite.color.a); subJSON.AddField("color", color); subJSON.AddField("colorBlendType", 0); //if (uiSprite.name == "PageBagChecked") //{ // Debug.Log("++==++==++"); // Debug.Log(uiSprite.isAnchored); // Debug.Log(uiSprite.bottomAnchor.absolute); // Debug.Log(uiSprite.bottomAnchor.target.name); //} UI2DSprite.Type type = uiSprite.type; subJSON.AddField("type", (int)type); UI2DSprite.Flip flipType = uiSprite.flip; subJSON.AddField("flip", (int)flipType); subJSON.AddField("fillCenter", uiSprite.centerType == UI2DSprite.AdvancedType.Sliced); subJSON.AddField("fillDir", (int)uiSprite.fillDirection); subJSON.AddField("fillAmount", uiSprite.fillAmount); subJSON.AddField("invertFill", uiSprite.invert); if (uiSprite.atlas != null) { string uuid = WXSpriteFrame.getSprite(uiSprite.atlas, uiSprite.spriteName, context.preset); if (uuid == null) { Debug.LogWarning("获取sprite失败: " + uiSprite.spriteName); } else { context.AddResource(uuid); } if (uuid != null) { subJSON.AddField("spriteFrame", uuid); } else { JSONObject nullJSON = new JSONObject(JSONObject.Type.NULL); subJSON.AddField("spriteFrame", nullJSON); } } else { JSONObject nullJSON = new JSONObject(JSONObject.Type.NULL); subJSON.AddField("spriteFrame", nullJSON); } subJSON.AddField("active", uiSprite.enabled); json.AddField("data", subJSON); return(json); } else { JSONObject json = new JSONObject(JSONObject.Type.OBJECT); json.AddField("type", "UISprite"); JSONObject subJSON = new JSONObject(JSONObject.Type.OBJECT); JSONObject color = new JSONObject(JSONObject.Type.ARRAY); color.Add(255f); color.Add(255f); color.Add(255f); color.Add(255f); subJSON.AddField("color", color); subJSON.AddField("colorBlendType", 0); subJSON.AddField("type", (int)UI2DSprite.Type.Simple); subJSON.AddField("flip", (int)UI2DSprite.Flip.Nothing); subJSON.AddField("fillCenter", false); subJSON.AddField("fillDir", (int)UI2DSprite.FillDirection.Horizontal); subJSON.AddField("fillAmount", 0); subJSON.AddField("invertFill", false); JSONObject nullJSON = new JSONObject(JSONObject.Type.NULL); subJSON.AddField("spriteFrame", nullJSON); subJSON.AddField("active", true); json.AddField("data", subJSON); 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", getTypeName()); json.AddField("data", data); data.AddField("active", true); // ngui prefab don't need binding script if (this.behaviour != null /* && !WXBridge.isNGUIPreset */) { var script = MonoScript.FromMonoBehaviour(this.behaviour); string path = new WXEngineScript(script).Export(context.preset); context.AddResource(path); data.AddField("__uuid", path); } if (this.behaviour != null) { Type myObjectType = behaviour.GetType(); FieldInfo[] fields = myObjectType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public); foreach (FieldInfo field in fields) { if (!field.IsDefined(typeof(SerializeField)) && !field.IsPublic) { continue; } WXMonoBehaviourPropertiesHandler.HandleProperty(field, behaviour, data, context); } } // clear {} json.GetField("data", (JSONObject _data) => { var shouldBeRemoved = new List <string>(); foreach (var _key in _data.keys) { // Debug.Log(_type); // Debug.Log(_data[_type] + " == " + _data[_type].GetType().ToString()); var _value = _data[_key].ToString(); // Debug.Log("key:"+_key+" value:"+_value); if (_data[_key].IsNull || _value == "{}") { shouldBeRemoved.Add(_key); // _data.RemoveField(_key); // Debug.Log("remove: " + _key); } } foreach (var k in shouldBeRemoved) { _data.RemoveField(k); } }); 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) { 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); 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); }
protected override JSONObject ToJSON(WXHierarchyContext context) { JSONObject json = new JSONObject(JSONObject.Type.OBJECT); JSONObject data = new JSONObject(JSONObject.Type.OBJECT); JSONObject effectNodeData = new JSONObject(JSONObject.Type.OBJECT); JSONObject pannerNodeData = new JSONObject(JSONObject.Type.OBJECT); data.AddField("effectNodeData", effectNodeData); data.AddField("pannerNodeData", pannerNodeData); json.AddField("type", getTypeName()); json.AddField("data", data); if ((UnityEngine.Object)audioSource.clip != (UnityEngine.Object)null) { WXAudioClip converter = new WXAudioClip(audioSource.clip, gameObject); string audioClipPath = converter.Export(context.preset); if (audioClipPath != null && audioClipPath != "") { data.AddField("clip", audioClipPath); effectNodeData.AddField("clip", audioClipPath); context.AddResource(audioClipPath); } } else { data.AddField("clip", JSONObject.nullJO); effectNodeData.AddField("clip", JSONObject.nullJO); } string outputAudioMixerGroup = ""; if ((UnityEngine.Object)audioSource.outputAudioMixerGroup != (UnityEngine.Object)null) { EditorUtility.DisplayDialog("Error", "暂不支持导出Audio Mixer Group", "确定"); } if (string.IsNullOrEmpty(outputAudioMixerGroup)) { data.AddField("output", JSONObject.nullJO); } else { data.AddField("output", outputAudioMixerGroup); } // audiosource本身的字段 data.AddField("audioPriority", (uint)audioSource.priority); data.AddField("playOnAwake", audioSource.playOnAwake); data.AddField("bypassEffects", audioSource.bypassEffects); data.AddField("bypassListenerEffects", audioSource.bypassListenerEffects); data.AddField("bypassReverbZones", audioSource.bypassReverbZones); data.AddField("reverbZoneMix", (float)audioSource.reverbZoneMix); // audiosourceNode字段 effectNodeData.AddField("id", this._genId()); effectNodeData.AddField("mute", audioSource.mute); effectNodeData.AddField("loop", audioSource.loop); effectNodeData.AddField("volume", (float)audioSource.volume); effectNodeData.AddField("pitch", (float)audioSource.pitch); effectNodeData.AddField("__typeName", "AudioSourceNode"); // pannerNode字段 pannerNodeData.AddField("id", this._genId()); pannerNodeData.AddField("stereoPan", (float)audioSource.panStereo); pannerNodeData.AddField("spatialBlend", (float)audioSource.spatialBlend); string rolloffMode; AudioRolloffModeMap.TryGetValue(audioSource.rolloffMode, out rolloffMode); pannerNodeData.AddField("distanceModel", rolloffMode); pannerNodeData.AddField("maxDistance", audioSource.maxDistance); pannerNodeData.AddField("minDistance", audioSource.minDistance); effectNodeData.AddField("__typeName", "AudioPannerNode"); return(json); }
protected override JSONObject ToJSON(WXHierarchyContext context) { JSONObject json = new JSONObject(JSONObject.Type.OBJECT); JSONObject data = new JSONObject(JSONObject.Type.OBJECT); JSONObject bindingsArr = new JSONObject(JSONObject.Type.OBJECT); json.AddField("type", getTypeName()); json.AddField("data", data); int timeUpdateMode; UpdateMode.TryGetValue(playableDirector.timeUpdateMode, out timeUpdateMode); data.AddField("timeUpdateMode", timeUpdateMode); data.AddField("playOnAwake", playableDirector.playOnAwake); // 貌似unity怎么搞playOnAwake都是false int wrapMode; WrapMode.TryGetValue(playableDirector.extrapolationMode, out wrapMode); data.AddField("wrapMode", wrapMode); data.AddField("initialTime", (float)playableDirector.initialTime); data.AddField("duration", (float)playableDirector.duration); data.AddField("sceneBindings", bindingsArr); TimelineAsset timelineAsset = (TimelineAsset)playableDirector.playableAsset; if ((UnityEngine.Object)timelineAsset != (UnityEngine.Object)null && timelineAsset.outputTrackCount > 0) // 有output { WXTimelineAssets converter = new WXTimelineAssets(timelineAsset, gameObject); string timelineAssetPath = converter.Export(context.preset); if (timelineAssetPath != null && timelineAssetPath != "") { data.AddField("playableAsset", timelineAssetPath); context.AddResource(timelineAssetPath); string playableAssetPath = AssetDatabase.GetAssetPath(timelineAsset); // timeline资源路径 IEnumerator <PlayableBinding> outputsEnumerator = timelineAsset.outputs.GetEnumerator(); List <TrackAsset> outputTracks = timelineAsset.GetOutputTracks().ToList();; int num = 0; while (outputsEnumerator.MoveNext()) // 遍历bindings { JSONObject bindingData = new JSONObject(JSONObject.Type.OBJECT); PlayableBinding binding = (PlayableBinding)outputsEnumerator.Current; var sourceObject = playableDirector.GetGenericBinding(binding.sourceObject); // 获取binding里sourceobject对应的entity string componentId = ""; string localId = WXTimelineAssets.GetTrackLocalIdByInstanceID(playableAssetPath, outputTracks[num].GetInstanceID()); if ((UnityEngine.Object)sourceObject != (UnityEngine.Object)null) { if (binding.sourceObject.GetType() == typeof(ActivationTrack)) // active track绑定的是entity { Transform transform = (sourceObject as GameObject).GetComponent(typeof(Transform)) as Transform; componentId = context.AddComponentInProperty( new WXTransform3DComponent(transform), transform ); } else if (binding.sourceObject.GetType() == typeof(AudioTrack)) // audio track 绑定AudioSource { componentId = context.AddComponentInProperty( new WXAudioSource((AudioSource)sourceObject, (GameObject)(sourceObject as AudioSource).gameObject), (AudioSource)sourceObject ); } else if (binding.sourceObject.GetType() == typeof(AnimationTrack)) // animation track 绑定Animator { Animator animator; if (sourceObject.GetType() == typeof(Animator)) { animator = sourceObject as Animator; componentId = context.AddComponentInProperty( new WXAnimator(animator, (sourceObject as Animator).gameObject), animator ); } else { animator = (sourceObject as GameObject).GetComponent <Animator>(); componentId = context.AddComponentInProperty( new WXAnimator(animator, (GameObject)sourceObject), animator ); } } else { EditorUtility.DisplayDialog("Error", "导出的Playable Director Bingdings格式不支持", "确定"); componentId = ""; } } else { componentId = ""; } if (string.IsNullOrEmpty(componentId)) { bindingsArr.AddField(localId, JSONObject.nullJO); } else { bindingsArr.AddField(localId, componentId); } num++; } } } else { data.AddField("playableAsset", JSONObject.nullJO); } return(json); }
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 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 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) { JSONObject json = new JSONObject(JSONObject.Type.OBJECT); json.AddField("type", "UISprite"); JSONObject subJSON = new JSONObject(JSONObject.Type.OBJECT); JSONObject color = new JSONObject(JSONObject.Type.ARRAY); color.Add(255f * uiTexture.color.r); color.Add(255f * uiTexture.color.g); color.Add(255f * uiTexture.color.b); color.Add(255f * uiTexture.color.a); subJSON.AddField("color", color); subJSON.AddField("colorBlendType", 0); UI2DSprite.Type type = uiTexture.type; subJSON.AddField("type", (int)type); UI2DSprite.Flip flipType = uiTexture.flip; subJSON.AddField("flip", (int)flipType); subJSON.AddField("fillCenter", uiTexture.centerType == UI2DSprite.AdvancedType.Sliced); subJSON.AddField("fillDir", (int)uiTexture.fillDirection); subJSON.AddField("fillAmount", uiTexture.fillAmount); subJSON.AddField("invertFill", uiTexture.invert); string texturePath = ""; if (uiTexture.mainTexture != null) { Texture2D texture2D = (Texture2D)uiTexture.mainTexture; if (texture2D != null) { string path = AssetDatabase.GetAssetPath(texture2D.GetInstanceID()); texturePath = new WXTexture(texture2D).Export(context.preset);// MaterialUtil.SaveTextureFile(texture2D); context.AddResource(texturePath); UISpriteData data = new UISpriteData(); data.width = uiTexture.mainTexture.width; data.height = uiTexture.mainTexture.height; WXSpriteFrame spriteFrame = new WXSpriteFrame(data, texturePath, path); string key = spriteFrame.Export(context.preset); subJSON.AddField("spriteFrame", key); context.AddResource(key); } } else { JSONObject nullJSON = new JSONObject(JSONObject.Type.NULL); subJSON.AddField("spriteFrame", nullJSON); } subJSON.AddField("active", uiTexture.enabled); json.AddField("data", subJSON); 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", "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); }
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); }