protected override JSONObject ExportResource(ExportPreset preset) { Cubemap cubemap = _cubemap; JSONObject jsonFile = new JSONObject(JSONObject.Type.OBJECT); jsonFile.AddField("desc", TextureUtil.getMeta(cubemap)); JSONObject m_files = new JSONObject(JSONObject.Type.OBJECT); TextureUtil.EnumTexFileExt ext = TextureUtil.ResolveFileExt(cubemap.format); for (int i = 0; i < 6; i++) { Texture2D texture2D = DuplicateTexture(cubemap, i); m_files.AddField( faceNames[i], AddFile( new WXCubeMapTextureImage(texture2D, ext, faceNames[i], unityAssetPath) ) ); } jsonFile.AddField("files", m_files); jsonFile.AddField("version", 2); return(jsonFile); }
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; }
protected override JSONObject ExportResource(ExportPreset preset) { JSONObject meta = JSONObject.Create("{\"file\": {}}"); JSONObject metadata = new JSONObject(); meta.AddField("data", metadata); byte[] content = WriteMeshFile(ref metadata); meta.GetField("file").AddField( "src", AddFile(new WXEngineMeshFile(unityAssetPath, meshName, content)) ); // 在importsetting里关联fbx文件 if (Path.GetExtension(unityAssetPath).ToLower() == ".fbx") { importSetting = new JSONObject(); WXRawResource fbx = new WXRawResource(unityAssetPath); string fbxExportedPath = fbx.Export(preset); importSetting.AddField("associateFbx", fbxExportedPath); AddDependencies(fbxExportedPath); } return(meta); }
private void ExportAllResourcesDirectories() { var res = ConfigManager.configEntry.exportDirectoryListConfig.exportDirectories; if (res == null || res.Count == 0) { EditorUtility.DisplayDialog("Resources目录配置", "未找到任何Resources目录或未添加至列表中", "ok"); return; } int i = 0; foreach (var r in res) { UnityEngine.Object dir = r.directory; if (dir != null) { EditorUtility.FocusProjectWindow(); Selection.activeObject = dir; if (r.isNGUI) { ExportPreset.GetExportPreset("ngui-prefabfolder").Export(); } else if (r.isUGUI) { ExportPreset.GetExportPreset("ugui-prefabfolder").Export(); } else { ExportPreset.GetExportPreset("prefabfolder").Export(); } i++; } } Debug.Log("导出资源文件夹: " + i); }
protected override JSONObject ExportResource(ExportPreset preset) { WXHierarchyContext hierarchyContext = new WXHierarchyContext(preset, prefabPath); // 初始化输出的JSON对象 JSONObject prefabJSONObject = new JSONObject(JSONObject.Type.OBJECT); JSONObject metaJson = new JSONObject(JSONObject.Type.OBJECT); prefabJSONObject.AddField("meta", metaJson); // 填充meta metaJson.AddField("name", exportName); metaJson.AddField("type", /*WXBeefBall.HierarchyType == WXBeefBall.EHierarchyType.TwoD ? "2D" : */ "3D"); JSONObject configJson = new JSONObject(JSONObject.Type.OBJECT); metaJson.AddField("config", configJson); //if (WXBeefBall.HierarchyType == WXBeefBall.EHierarchyType.TwoD) //{ // JSONObject resolutionJson = new JSONObject(JSONObject.Type.ARRAY); // resolutionJson.Add(1280); // resolutionJson.Add(720); // configJson.AddField("resolution", resolutionJson); //} // 开始遍历 WXEntity rootEntity = /*WXBeefBall.HierarchyType == WXBeefBall.EHierarchyType.TwoD ? * hierarchyContext.Iterate2DGameObject(prefabRoot) : * hierarchyContext.Iterate3DGameObject(prefabRoot);*/hierarchyContext.IterateGameObject(prefabRoot, null); prefabJSONObject.AddField("gameObjectList", hierarchyContext.GetGameObjectListJSON()); prefabJSONObject.AddField("componentList", hierarchyContext.GetComponentListJSON()); JSONObject editorInfo = new JSONObject(JSONObject.Type.OBJECT); editorInfo.AddField("assetVersion", 2); prefabJSONObject.AddField("editorInfo", editorInfo); Debug.Log("Export Prefab " + prefabPath + " " + hierarchyContext.resourceList.Count); //WXResourceStore.AddJSONResource( // prefabPath, // "prefab", // prefabJSONObject, // metadata, // hierarchyContext.resourceList, // assetVersion // //AssetDatabase.GetAssetDependencyHash(prefabPath).ToString() //); //return prefabPath; foreach (string resource in hierarchyContext.resourceList) { AddDependencies(resource); } return(prefabJSONObject); }
protected override JSONObject ExportResource(ExportPreset preset) { if (string.IsNullOrEmpty(unityAssetPath)) { Debug.LogError("Baked reflection probe null."); return(null); } JSONObject jsonFile = new JSONObject(JSONObject.Type.OBJECT); jsonFile.AddField("desc", TextureUtil.getMeta(envMap)); JSONObject m_files = new JSONObject(JSONObject.Type.OBJECT); // get file type TextureUtil.EnumTexFileExt ext = TextureUtil.ResolveFileExt(envMap.format); for (int i = 0; i < 6; i++) { Texture2D texture2D = DuplicateTexture(envMap, i); Texture2D flipV2D = VerticalFlipTexture(texture2D); m_files.AddField( faceNames[i], AddFile( new WXCubeMapTextureImage(flipV2D, ext, faceNames[i], unityAssetPath) ) ); } jsonFile.AddField("files", m_files); jsonFile.AddField("version", 2); return(jsonFile); }
// 导出资源 protected override JSONObject ExportResource(ExportPreset preset) { JSONObject timelineJSON = new JSONObject(JSONObject.Type.OBJECT); JSONObject root = new JSONObject(JSONObject.Type.OBJECT); JSONObject rootTrackIndexArr = new JSONObject(JSONObject.Type.ARRAY); JSONObject trackListArr = new JSONObject(JSONObject.Type.ARRAY); JSONObject clipListArr = new JSONObject(JSONObject.Type.ARRAY); timelineJSON.AddField("root", root); timelineJSON.AddField("trackList", trackListArr); timelineJSON.AddField("clipList", clipListArr); root.AddField("name", timelineAsset.name); root.AddField("fixedDuration", (float)timelineAsset.fixedDuration); int durationMode; DurationModeMap.TryGetValue(timelineAsset.durationMode, out durationMode); root.AddField("durationMode", durationMode); root.AddField("frameRate", timelineAsset.editorSettings.fps); root.AddField("tracks", rootTrackIndexArr); ExportRootTrack(rootTrackIndexArr, trackListArr, clipListArr); // 导出rootTrack return(timelineJSON); }
protected override JSONObject ExportResource(ExportPreset preset) { JSONObject audioClipJSON = base.ExportResource(preset); JSONObject dataJSON = audioClipJSON.GetField("data"); JSONObject editorInfoJSON = audioClipJSON.GetField("editorInfo"); if (dataJSON == null) { dataJSON = new JSONObject(JSONObject.Type.OBJECT); audioClipJSON.AddField("data", dataJSON); } if (editorInfoJSON == null) { editorInfoJSON = new JSONObject(JSONObject.Type.OBJECT); audioClipJSON.AddField("editorInfo", editorInfoJSON); } editorInfoJSON.AddField("name", audioClip.name); dataJSON.AddField("length", audioClip.length); dataJSON.AddField("preloadAudioData", true); AssetImporter importer = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(audioClip.GetInstanceID())); AudioImporter audioImporter = importer as AudioImporter; int loadType; LoadTypeMap.TryGetValue(audioImporter.defaultSampleSettings.loadType, out loadType); audioClipJSON.AddField("loadType", loadType); /* * AssetImporter importer = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(audioClip.GetInstanceID())); * AudioImporter audioImporter = importer as AudioImporter; * PropertyInfo inspectorModeInfo = typeof(UnityEditor.SerializedObject).GetProperty ("inspectorMode", BindingFlags.NonPublic | BindingFlags.Instance); * UnityEditor.SerializedObject serializedObject = new UnityEditor.SerializedObject (audioImporter); * inspectorModeInfo.SetValue(serializedObject, UnityEditor.InspectorMode.Debug, null); * UnityEditor.SerializedProperty normalize = serializedObject.FindProperty ("m_Normalize"); * audioClipJSON.AddField("normalize", normalize.boolValue); * audioClipJSON.AddField("ambisonic", audioImporter.ambisonic); * audioClipJSON.AddField("conversionMode", audioImporter.defaultSampleSettings.conversionMode); * audioClipJSON.AddField("quality", audioImporter.defaultSampleSettings.quality); * audioClipJSON.AddField("sampleRateOverride", audioImporter.defaultSampleSettings.sampleRateOverride); * * int compressionFormat; * CompressionFormatMap.TryGetValue(audioImporter.defaultSampleSettings.compressionFormat, out compressionFormat); * audioClipJSON.AddField("compressionFormat", compressionFormat); * * int sampleRateSetting; * SampleRateSettingMap.TryGetValue(audioImporter.defaultSampleSettings.sampleRateSetting, out sampleRateSetting); * audioClipJSON.AddField("sampleRateSetting", sampleRateSetting); * * int loadType; * LoadTypeMap.TryGetValue(audioImporter.defaultSampleSettings.loadType, out loadType); * audioClipJSON.AddField("loadType", loadType); * * audioClipJSON.AddField("forceToMono", audioImporter.forceToMono); * audioClipJSON.AddField("loadInBackground", audioImporter.loadInBackground); * audioClipJSON.AddField("preloadAudioData", audioImporter.preloadAudioData); * audioClipJSON.AddField("threeD", audioImporter.threeD); */ return(audioClipJSON); }
protected override JSONObject ExportResource(ExportPreset preset) { hierarchyContext = new WXHierarchyContext(preset, scenePath); // 初始化输出的JSON对象 JSONObject sceneJSONObject = new JSONObject(JSONObject.Type.OBJECT); JSONObject metaJson = new JSONObject(JSONObject.Type.OBJECT); sceneJSONObject.AddField("meta", metaJson); // 填充meta metaJson.AddField("name", exportName); metaJson.AddField("type", /*WXBeefBall.HierarchyType == WXBeefBall.EHierarchyType.TwoD ? "2D" : */ "3D"); JSONObject configJson = new JSONObject(JSONObject.Type.OBJECT); metaJson.AddField("config", configJson); JSONObject lightJson = new JSONObject(JSONObject.Type.OBJECT); GetLightConfig(lightJson, hierarchyContext); configJson.AddField("light", lightJson); GameObject[] root = gameScene.GetRootGameObjects(); // WXEntity rootObj = hierarchyContext.MakeEntity(null); // rootObj.active = true; // rootObj.name = "Scene<" + exportName + ">"; // rootObj.components.Add(hierarchyContext.AddComponent(new WXTransform3DComponent(null, true), null)); foreach (GameObject obj in root) { if ((preset.exportConfigs as HierarchyExportConfig).ignoreNonActive && (!obj.activeSelf || !obj.activeInHierarchy) ) { continue; } obj.name = "Scene<" + exportName + ">"; // 开始遍历 WXEntity leafEntity = hierarchyContext.IterateGameObject(obj); } sceneJSONObject.AddField("gameObjectList", hierarchyContext.GetGameObjectListJSON()); sceneJSONObject.AddField("componentList", hierarchyContext.GetComponentListJSON()); foreach (string resource in hierarchyContext.resourceList) { AddDependencies(resource); } JSONObject editorInfo = new JSONObject(JSONObject.Type.OBJECT); editorInfo.AddField("assetVersion", 2); sceneJSONObject.AddField("editorInfo", editorInfo); return(sceneJSONObject); }
protected override JSONObject ExportResource(ExportPreset preset) { //JSONObject meta = JSONObject.Create ("{\"file\": {}}"); JSONObject metadata = new JSONObject(); WritePhysicsMaterial(ref metadata); //meta.AddField("data", metadata); //meta.AddField("version", 2); return(metadata); }
protected override JSONObject ExportResource(ExportPreset preset) { JSONObject metadata = JSONObject.Create("{\"file\": {}}"); string file_type = GetFileType(unityAssetPath); metadata.GetField("file").SetField("src", AddFile(new WXEngineCopyFile(unityAssetPath, file_type))); return(metadata); }
protected override JSONObject ExportResource(ExportPreset preset) { if (avatar.isHuman) { isHuman = GetHumanDescription(avatar, ref desc); if (isHuman) { foreach (var pair in desc.human) { humanMap.Add(pair.humanName, pair.boneName); } } } JSONObject avatarJSON = new JSONObject(JSONObject.Type.OBJECT); /* * { * avatar:{ * path, * linkSprites * } * } */ int id = -2; // GetAvatarNodeData(gameObject, rootNode, gameObject, ref id); bool succ = false; JSONObject avatarRootNodeJSON = GetAvatarRootNodeJSON(gameObject, gameObject, ref id, ref succ); if (avatarRootNodeJSON == null) { return(null); } JSONObject paths = new JSONObject(JSONObject.Type.ARRAY); AssetImporter importer = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(avatar.GetInstanceID())); ModelImporter mImporter = importer as ModelImporter; if (mImporter != null) { for (int k = 0; k < mImporter.extraExposedTransformPaths.Length; k++) { paths.Add(mImporter.extraExposedTransformPaths[k]); } } avatarJSON.AddField("version", "1"); avatarJSON.AddField("rootNode", avatarRootNodeJSON); avatarJSON.AddField("optimized", mImporter.optimizeGameObjects); string avatarPath = Path.GetFullPath(Directory.GetParent(Application.dataPath) + "/" + AssetDatabase.GetAssetPath(avatar.GetInstanceID())); float scale = (Path.GetExtension(avatarPath).ToLower() == ".fbx" && mImporter.useFileUnits) ? 0.01f : 1.0f; avatarJSON.AddField("scaleFactor", succ ? scale : 1.0f); avatarJSON.AddField("paths", paths); avatarJSON.AddField("version", 2); return(avatarJSON); }
public WXHierarchyContext(ExportPreset _preset, string _resourcePath) { // 初始化列表 gameObjectList = new List <WXEntity>(); componentList = new List <WXComponent>(); componentDictionary = new Dictionary <string, WXComponent>(); resourceList = new List <string>(); prefabRootDict = new Dictionary <GameObject, WXEntity>(); preset = _preset; resourcePath = _resourcePath; }
protected override JSONObject ExportResource(ExportPreset preset) { JSONObject avatarMaskJSON = new JSONObject(JSONObject.Type.OBJECT); avatarMaskJSON.AddField("name", avatarMask.name); JSONObject elementsJSON = new JSONObject(JSONObject.Type.OBJECT); avatarMaskJSON.AddField("paths", elementsJSON); for (int i = 0; i < avatarMask.transformCount; i++) { elementsJSON.AddField("/" + avatarMask.GetTransformPath(i), avatarMask.GetTransformActive(i) ? 1 : 0); } return(avatarMaskJSON); }
protected override JSONObject ExportResource(ExportPreset preset) { var realPath = Path.Combine(BridgeExport.TMP_BINDING_CACHE, GetExportPath()); if (ExportLogger.LOGGING) { ExportLogger.AddLog(new ExportLogger.Log(ExportLogger.Log.Type.System, "File: " + realPath + " Exists: " + File.Exists(realPath))); } AddFile(new WXScriptFile(realPath, GetExportPath())); dontExportDescriptionJSON = true; return(null); }
protected override JSONObject ExportResource(ExportPreset preset) { if (material == null) { return(null); } string name = material.shader.name; JSONObject jsonFile = new JSONObject(JSONObject.Type.OBJECT); WXMaterialParser parser; string parserName = name; if (name == "Skybox/6 Sided" || name == "Skybox/Cubemap") { parserName = "Skybox"; } HierarchyExportConfig exportConfigs = preset.exportConfigs as HierarchyExportConfig; if (!parsers.ContainsKey(name) && exportConfigs.createEffectTemplate) { parserName = "CustomShader"; } if (parsers.TryGetValue(parserName, out parser)) { jsonFile = parser.parse(this, AddDependencies); } else if (component != null) { ErrorUtil.ExportErrorReporter.create() .setResource(this) .setGameObject(component.gameObject) .error(ErrorUtil.ErrorCode.Material_UnsupportedShader, "遇到了不支持的Shader: " + name); } string effectName = jsonFile.GetField("effect").GetRawString(); string effectUUID; if (buildInEffectNameToUUIDMap.TryGetValue(effectName, out effectUUID)) { jsonFile.SetField("effect", effectUUID); } JSONObject editorInfo = new JSONObject(JSONObject.Type.OBJECT); editorInfo.AddField("assetVersion", 3); jsonFile.AddField("editorInfo", editorInfo); return(jsonFile); }
private void ExportAllScenes() { var activeScene = EditorSceneManager.GetActiveScene(); string currentScenePath = ""; if (activeScene != null && activeScene.path != "") { currentScenePath = EditorSceneManager.GetActiveScene().path; } int i = 0; var scenes = sceneExportConfig.exportScenes; if (scenes != null && scenes.Count > 0) { scenes.ForEach(scene => { var path = AssetDatabase.GetAssetPath(scene.scene); try { EditorSceneManager.OpenScene(path); if (scene.isNGUI) { ExportPreset.GetExportPreset("ngui-rootScene").WillPresetShow(); ExportPreset.GetExportPreset("ngui-rootScene").Export(); } else if (scene.isUGUI) { ExportPreset.GetExportPreset("ugui-rootScene").WillPresetShow(); ExportPreset.GetExportPreset("ugui-rootScene").Export(); } else { ExportPreset.GetExportPreset("scene").Export(); } i++; } catch (ArgumentException e) { // 被添加的Scene不存在,不做处理 } }); } if (currentScenePath != "") { EditorSceneManager.OpenScene(currentScenePath); } Debug.Log("导出场景: " + i); }
protected override JSONObject ExportResource(ExportPreset preset) { JSONObject meta = JSONObject.Create("{\"file\": {}}"); JSONObject metadata = new JSONObject(); meta.AddField("data", metadata); byte[] content = WriteMeshFile(ref metadata); meta.GetField("file").AddField( "src", AddFile(new WXEngineMeshFile(unityAssetPath, mesh.name, content)) ); return(meta); }
protected override JSONObject ExportResource(ExportPreset preset) { JSONObject metadata = JSONObject.Create("{\"data\":{}, \"file\":{}}"); string texturePath = AddFile(new TextureImageFile(texture2D)); metadata.GetField("file").AddField("src", texturePath); metadata.SetField("data", TextureUtil.getMeta(texture2D)); var editorInfo = new JSONObject(JSONObject.Type.OBJECT); editorInfo.AddField("assetVersion", 2); metadata.AddField("editorInfo", editorInfo); return(metadata); }
protected override JSONObject ExportResource(ExportPreset preset) { Cubemap cubemap = _cubemap; JSONObject jsonFile = new JSONObject(JSONObject.Type.OBJECT); jsonFile.AddField("desc", TextureUtil.getMeta(cubemap)); JSONObject m_files = new JSONObject(JSONObject.Type.OBJECT); TextureUtil.EnumTexFileExt ext = TextureUtil.ResolveFileExt(cubemap.format); for (int i = 0; i < 6; i++) { Texture2D texture2D = DuplicateTexture(cubemap, i); /* * this behavior is by design: if we speak about cubemaps they are intended to be sampled for reflection, * i.e. with reflection vector, which means that we "want" image to be flipped both vert/horz * and this is exactly what cubemap inspector does with images you assign to slots. * When you copy textures you will get "mirrored" reflection (and you can see this in the preview too) */ if (faceNames[i] != "top" && faceNames[i] != "bottom") { Color[] colors = texture2D.GetPixels(0, 0, texture2D.width, texture2D.height); System.Array.Reverse(colors, 0, colors.Length); Texture2D t = new Texture2D(texture2D.width, texture2D.height, texture2D.format, true); //Debug.Log("Pixel size:" + capx + " " + capy + " " + capwidth + " " + capheight); //t.ReadPixels(new Rect(capx, capy, capwidth, capheight), 0, 0, false); t.SetPixels(colors); t.Apply(); texture2D = t; } m_files.AddField( faceNames[i], AddFile( new WXCubeMapTextureImage(texture2D, ext, faceNames[i], path) ) ); } jsonFile.AddField("files", m_files); jsonFile.AddField("version", 2); return(jsonFile); }
protected override JSONObject ExportResource(ExportPreset preset) { string fileName = Path.GetFileName(unityAssetPath); string lowerFileName = fileName.ToLower(); string _fontPath = unityAssetPath.Replace(fileName, lowerFileName); JSONObject jsonFile = JSONObject.Create("{\"file\": {}}"); jsonFile.GetField("file").AddField( "src", AddFile(new WXEngineCopyFile(_fontPath, "font")) ); jsonFile.AddField("version", 2); return(jsonFile); }
public string Export(ExportPreset preset) { usingPreset = preset; if (!ExportStore.IsFileConverted(GetExportPath(), DoGetHash())) { if (DoExport()) { return(GetExportPath()); } else { return(""); } } return(GetExportPath()); }
protected override JSONObject ExportResource(ExportPreset preset) { if (material == null) { return(null); } string name = material.shader.name; JSONObject jsonFile = new JSONObject(JSONObject.Type.OBJECT); WXMaterialParser parser; string parserName = name; if (name == "Skybox/6 Sided" || name == "Skybox/Cubemap") { parserName = "Skybox"; } HierarchyExportConfig exportConfigs = preset.exportConfigs as HierarchyExportConfig; if (!parsers.ContainsKey(name) && exportConfigs.createEffectTemplate) { parserName = "CustomShader"; } if (parsers.TryGetValue(parserName, out parser)) { jsonFile = parser.parse(this, AddDependencies); } else if (component != null) { Debug.LogErrorFormat("WXBeefBallMaterial: Unsupported Shader {0} in {1}, which {2} is using!", name, unityAssetPath, component.name); } string effectName = jsonFile.GetField("effect").GetRawString(); string effectUUID; if (buildInEffectNameToUUIDMap.TryGetValue(effectName, out effectUUID)) { jsonFile.SetField("effect", effectUUID); } JSONObject editorInfo = new JSONObject(JSONObject.Type.OBJECT); editorInfo.AddField("assetVersion", 3); jsonFile.AddField("editorInfo", editorInfo); return(jsonFile); }
internal static string getSprite(Sprite sprite, ExportPreset preset) { Texture2D texture2D = sprite.texture as Texture2D; string res = null; if (texture2D != null) { string picturePath = AssetDatabase.GetAssetPath(texture2D.GetInstanceID()); string texturePath = new WXTexture(texture2D).Export(preset); WXUGUISpriteFrame spriteConverter = new WXUGUISpriteFrame(sprite, texturePath, picturePath); string uuid = spriteConverter.Export(preset); return(uuid); } return(res); }
protected override JSONObject ExportResource(ExportPreset preset) { if (string.IsNullOrEmpty(unityAssetPath)) { Debug.LogError("Baked reflection probe null."); return(null); } JSONObject metadata = JSONObject.Create("{\"data\":{}, \"file\":{}}"); string texturePath = AddFile(new TextureImageFile(envMap)); metadata.GetField("file").AddField("src", texturePath); metadata.SetField("data", TextureUtil.getMeta(envMap)); var editorInfo = new JSONObject(JSONObject.Type.OBJECT); editorInfo.AddField("assetVersion", 2); metadata.AddField("editorInfo", editorInfo); return(metadata); }
protected override JSONObject ExportResource(ExportPreset preset) { float[] rect = { data.x, data.y, data.width, data.height }; JSONObject frameJSON = new JSONObject(JSONObject.Type.OBJECT); frameJSON.AddField("texture", texturePath); if (data.hasPadding) { JSONObject trimJSON = new JSONObject(JSONObject.Type.ARRAY); trimJSON.Add(data.paddingTop); trimJSON.Add(data.paddingRight); trimJSON.Add(data.paddingBottom); trimJSON.Add(data.paddingLeft); frameJSON.AddField("trim", trimJSON); } JSONObject rectJSON = new JSONObject(JSONObject.Type.ARRAY); rectJSON.Add(rect[0]); rectJSON.Add(rect[1]); rectJSON.Add(rect[2]); rectJSON.Add(rect[3]); frameJSON.AddField("rect", rectJSON); if (data.hasBorder) { float[] slicedRect = { data.borderLeft, data.borderTop, rect[2] - (data.borderLeft + data.borderRight), rect[3] - (data.borderTop + data.borderBottom) }; JSONObject innerRectJSON = new JSONObject(JSONObject.Type.ARRAY); innerRectJSON.Add(slicedRect[0]); innerRectJSON.Add(slicedRect[1]); innerRectJSON.Add(slicedRect[2]); innerRectJSON.Add(slicedRect[3]); frameJSON.AddField("slicedRect", innerRectJSON); } //JSONObject depJSON = new JSONObject(JSONObject.Type.ARRAY); //depJSON.Add(picturePath); // List<string> dependencies = new List<string>(); // dependencies.Add(picturePath); AddDependencies(texturePath); frameJSON.AddField("version", 2); return(frameJSON); }
protected override JSONObject ExportResource(ExportPreset preset) { float[] rect = { data.rect.x, data.rect.y, data.rect.width, data.rect.height }; JSONObject frameJSON = new JSONObject(JSONObject.Type.OBJECT); frameJSON.AddField("texture", texturePath); /*var style = data.style; * if (style) * { * JSONObject trimJSON = new JSONObject(JSONObject.Type.ARRAY); * trimJSON.Add(style.paddingTop); * trimJSON.Add(style.paddingRight); * trimJSON.Add(style.paddingBottom); * trimJSON.Add(style.paddingLeft); * frameJSON.AddField("trim", trimJSON); * } */ JSONObject rectJSON = new JSONObject(JSONObject.Type.ARRAY); rectJSON.Add(rect[0]); rectJSON.Add(rect[1]); rectJSON.Add(rect[2]); rectJSON.Add(rect[3]); frameJSON.AddField("rect", rectJSON); /* if (style) * { * float[] slicedRect = { style.borderLeftWidth, style.borderTopWidth, rect[2] - (style.borderLeftWidth + style.borderRightWidth), rect[3] - (style.borderTopWidth + style.borderBottomWidth) }; * JSONObject innerRectJSON = new JSONObject(JSONObject.Type.ARRAY); * innerRectJSON.Add(slicedRect[0]); * innerRectJSON.Add(slicedRect[1]); * innerRectJSON.Add(slicedRect[2]); * innerRectJSON.Add(slicedRect[3]); * frameJSON.AddField("slicedRect", innerRectJSON); * } */ AddDependencies(texturePath); frameJSON.AddField("version", 2); return(frameJSON); }
internal static string getSprite(UIAtlas atlas, string uispriteName, ExportPreset preset) { Material atlasMaterial = atlas.spriteMaterial; Texture2D texture2D = (Texture2D)atlasMaterial.GetTexture("_MainTex"); string res = null; if (texture2D != null) { string picturePath = AssetDatabase.GetAssetPath(texture2D.GetInstanceID()); //Texture2D copyTexture = DuplicateTexture(texture2D); //picturePath = path.Split('.')[0] + ".png"; string texturePath = new WXTexture(texture2D).Export(preset); JSONObject metadata = TextureUtil.getMeta(texture2D); BetterList <string> allSpriteList = atlas.GetListOfSprites(); string[] list = allSpriteList.ToArray(); foreach (string spriteName in list) { UISpriteData currentData = atlas.GetSprite(spriteName); WXSpriteFrame spriteConverter = new WXSpriteFrame(currentData, texturePath, picturePath); string uuid = spriteConverter.Export(preset); // 这里不需要了,外部去给hierarchyContext addResource就好 if (spriteName == uispriteName) { res = uuid; return(res); // WXBeefBallExportContext.addDep(uuid); } //else //{ // WXBeefBallExportContext.addNoDependence(uuid); //} } } return(res); }
public static void writeGroup(WXResource resource, ExportPreset preset) { try { EditorUtility.DisplayProgressBar( "导出资源", "资源读取中...", 0.33f ); string resourcePath = resource.Export(preset); EditorUtility.DisplayProgressBar( "导出资源", "文件写入中...", 0.66f ); string packageName = WXUtility.GetFileNameFromPath(resourcePath); if (packageName == "") { packageName = "Untitled"; } ExportStore.GenerateResourcePackage( packageName, resourcePath ); } catch (Exception e) { Debug.LogError(e.Message); Debug.LogError(e.StackTrace); } finally { EditorUtility.ClearProgressBar(); } }
static NGUIAssetExportPreset() { ExportPreset.registerExportPreset("ngui-asset", new NGUIAssetExportPreset()); }