protected override void DoExport() { // 把所有开发者ts源代码文件带上 List <string> tsFilePaths = new List <string>(); this.findTSRecursive( basePath, tsFilePaths ); List <string> scriptResources = new List <string>(); foreach (string tsPath in tsFilePaths) { PuertsSourceCodeScriptFile file = new PuertsSourceCodeScriptFile( tsPath, "Assets/puerts/src/" + tsPath.Substring(tsPath.IndexOf(basePath) + basePath.Length) ); scriptResources.Add(new WXEngineScriptResource(file).Export(this)); } // 把puerts生成的dts文件带上 PuertsSourceCodeScriptFile dtsFile = new PuertsSourceCodeScriptFile( Path.Combine(Application.dataPath, "Gen/Typing/csharp/index.d.ts"), "Assets/puerts/dts/csharp.d.ts" ); scriptResources.Add(new WXEngineScriptResource(dtsFile).Export(this)); // 把adaptor带上并且放入node_modules string[] adaptorFiles = { Application.dataPath + "/WXUnityTool-Puerts/res~/puerts-beefball/index.js", Application.dataPath + "/WXUnityTool-Puerts/res~/puerts-beefball/minigame-adaptor-lib-patch.js", Application.dataPath + "/WXUnityTool-Puerts/res~/puerts-beefball/minigame-adaptor-lib.js", Application.dataPath + "/WXUnityTool-Puerts/res~/puerts-beefball/minigame-adaptor-lib.meta.js", Application.dataPath + "/WXUnityTool-Puerts/res~/puerts-beefball/minigame-adaptor.js", Application.dataPath + "/WXUnityTool-Puerts/res~/puerts-beefball/package.json", Application.dataPath + "/WXUnityTool-Puerts/res~/puerts-beefball/puerts-beefball.d.ts", Application.dataPath + "/WXUnityTool-Puerts/res~/puerts-beefball/PuertsLogic.ts" }; foreach (string adaptorFile in adaptorFiles) { scriptResources.Add( new WXEngineScriptResource( new PuertsSourceCodeScriptFile( adaptorFile, Path.Combine("Assets/puerts/lib/adaptor/", Path.GetFileName(adaptorFile)) ) ).Export(this) ); } ExportStore.GenerateResourcePackage("puerts", scriptResources); }
private void PackFiles(string pkgName, string dirPath) { if (!Directory.Exists(dirPath)) { return; } EditorUtility.DisplayProgressBar("插件代码打包", "", 0.0f); var files = Directory.EnumerateFiles(dirPath, "*.js", SearchOption.AllDirectories).ToList(); List <string> allRecursiveAssets = new List <string>(); // all converted scripts var t = 0; foreach (var file in files) { // bridge plugin blacklist var name = Path.GetFileName(file); // Debug.Log(name); // 插件代码不打包这几个文件 if (name.Equals("minigame-adaptor-lib.js") || name.Equals("minigame-adaptor-lib.meta.js") || name.Equals("minigame-adaptor-lib-patch.js")) { continue; } JSONObject metadata = new JSONObject(JSONObject.Type.OBJECT); var cutIndex = Path.GetFullPath(file).IndexOf(dirPath) + dirPath.Length + 1; // +1 : '/' string path = Path.GetFullPath(file).Substring(cutIndex).Replace('\\', '/'); string content = File.ReadAllText(file); ExportStore.AddTextFile(path, content, WXUtility.GetMD5FromString(content)); List <string> useFile = new List <string>(); useFile.Add(path); ExportStore.AddResource(path, "script", null, useFile); allRecursiveAssets.Add(path); EditorUtility.DisplayProgressBar("插件代码打包", "", t++ / files.Count); } ExportStore.GenerateResourcePackage( pkgName, allRecursiveAssets ); }
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(); } }
protected override void DoExport() { var build = DirectoryBuilder.GetDirectory("build"); // check cache var projectDir = new DirectoryInfo(build["Project"].FullPath); // Debug.Log(projectDir.GetFiles().Length); if (!projectDir.Exists || projectDir.GetFiles() == null || projectDir.GetFiles().Length <= 1) { BridgeExport.ExportCodeMenu(); } // convert // BridgeExport.ExportCode(); // EditorUtility.ClearProgressBar(); // BridgeExport.isProcessing = false; EditorUtility.DisplayProgressBar("代码导出", "", 0.0f); var dirPath = BridgeExport.PROJECT_CODE_PATH; var files = Directory.EnumerateFiles(dirPath, "*.js", SearchOption.AllDirectories).ToList(); List <string> allRecursiveAssets = new List <string>(); // all converted scripts var t = 0; foreach (var file in files) { // bridge plugin blacklist var name = Path.GetFileName(file); // Debug.Log(name); // 使用引擎插件不打包这几个文件,以节省代码包体积 if (WXBridge.isWXBridgePlugin && ( name.Equals("minigame-adaptor-lib.js") || name.Equals("minigame-adaptor-lib.meta.js") || name.Equals("minigame-adaptor-lib-patch.js"))) { continue; } JSONObject metadata = new JSONObject(JSONObject.Type.OBJECT); metadata.AddField("version", 1); // string path = Path.GetFullPath(file).Replace(Path.Combine(Application.dataPath.Replace("Assets", ""), "__tmp_dist_script~"), "Assets"); var cutIndex = Path.GetFullPath(file).IndexOf(dirPath) + dirPath.Length + 1; // +1 : '/' string path = Path.GetFullPath(file).Substring(cutIndex).Replace('\\', '/'); // Debug.Log(path); // Debug.Log(file + "===" + path); // Debug.Log(path); string content = File.ReadAllText(file); ExportStore.AddTextFile(path, content, WXUtility.GetMD5FromString(content)); List <string> useFile = new List <string>(); useFile.Add(path); ExportStore.AddResource(path, "script", null, useFile); allRecursiveAssets.Add(path); EditorUtility.DisplayProgressBar("代码导出", "", t++ / files.Count); } // var libs = Directory.EnumerateFiles(Path.Combine(bridgeRootPath, "lib"), "*.lib"); var libs = Directory.EnumerateFiles(DirectoryBuilder.GetDirectory("references")["Adaptor"].FullPath, "*.lib"); // Debug.Log(libs); foreach (var lib in libs) { var name = Path.GetFileName(lib); // Debug.Log(name); // bridge plugin blacklist // 使用引擎插件的情况 if (WXBridge.isWXBridgePlugin) { // 如果使用了插件但是要用自己的adaptor.js,这个文件也要打包 if (!WXBridge.isWXBridgePluginAdaptor) { if (!name.Equals("minigame-adaptor-util.js.lib") && !name.Equals("minigame-adaptor-config.js.lib") && !name.Equals("minigame-adaptor.js.lib")) { continue; } } else { if (!name.Equals("minigame-adaptor-util.js.lib") && !name.Equals("minigame-adaptor-config.js.lib")) { continue; } } } JSONObject metadata = new JSONObject(JSONObject.Type.OBJECT); metadata.AddField("version", 1); string path = name.Substring(0, name.Length - 4); // 配置文件内容根据插件的配置来生成 if (name.Equals("minigame-adaptor-config.js.lib")) { // var content = String.Format("module.exports = {{\r\n userMiniGameAdaptorPlugin:{0},\r\n userMiniGameAdaptorJs:{1},\r\n pluginAlias:'WXBridge'\r\n}}", WXBridge.isWXBridgePlugin ? 1 : 0, WXBridge.isWXBridgePluginAdaptor ? 1 : 0); var content = ScriptExportHelper.ExportGameConfig(); ExportStore.AddTextFile(path, content, WXUtility.GetMD5FromString(content)); } else { string content = File.ReadAllText(lib); ExportStore.AddTextFile(path, content, WXUtility.GetMD5FromString(content)); } List <string> useFile = new List <string>(); useFile.Add(path); ExportStore.AddResource(path, "script", null, useFile); allRecursiveAssets.Add(path); } // game config js // { // JSONObject metadata = new JSONObject(JSONObject.Type.OBJECT); // metadata.AddField("version", 1); // string path = "Assets/bridge_game_config.js"; // JSONObject content = ScriptExportHelper.ExportSceneJson(); // WXExportStore.AddJSONFile(path, content, WXUtility.GetMD5FromString(content.ToString())); // List<string> useFile = new List<string>(); // useFile.Add(path); // WXExportStore.AddResource(path, "script", null, useFile); // allRecursiveAssets.Add(path); // } //string savePath = Path.Combine(SAVE_BASE_PATH, "Scripts.mgepackage/"); //JSONObject manifestRoot = new JSONObject(JSONObject.Type.OBJECT); //manifestRoot.AddField("resourceMeta", exportContext.writeResourcesTo(savePath, allRecursiveAssets)); //wxFileUtil.SaveJsonFile(manifestRoot, savePath + "group.manifest.json"); ExportStore.GenerateResourcePackage( "WXScripts", allRecursiveAssets ); EditorUtility.ClearProgressBar(); Debug.Log("导出工程代码: 1"); }
protected override void DoExport() { EditorUtility.ClearProgressBar(); BridgeExport.isProcessing = false; List <string> allRecursiveAssets = new List <string>(); // string choosedPath = GetExportPath(); // string savePath = Path.Combine(choosedPath, "Assets/"); var savePath = Path.Combine(ExportStore.storagePath, "Assets/"); updateRecourcesDir(); int totalCount = 0; string [] arr_dir = dirs.ToArray(); JSONObject jsonConfig = new JSONObject(JSONObject.Type.ARRAY); if (arr_dir.Length > 0) { for (int index = 0; index < supportedTypes.Length; index++) { string filter = "t:" + supportedTypes[index]; string[] guids = AssetDatabase.FindAssets(filter, arr_dir); // Debug.Log(guids.Length); if (guids.Length == 0) { continue; } JSONObject category = new JSONObject(JSONObject.Type.OBJECT); JSONObject data = new JSONObject(JSONObject.Type.ARRAY); category.AddField("type", supportedTypes[index]); category.AddField("files", data); var t = 0; HashSet <string> setFiles = new HashSet <string>(); for (int i = 0; i < guids.Length; i++) { string path = AssetDatabase.GUIDToAssetPath(guids[i]); if (path.StartsWith("Assets")) { path = path.Substring(6); } string absolutePath = Path.Combine(Application.dataPath, path); // #if UNITY_EDITOR_WIN // string absolutePath = Application.dataPath + "\\" + path; // #else // string absolutePath = Application.dataPath + "/" + path; // #endif // string filename = System.IO.Path.GetFileName(absolutePath); string copyToPath = Path.Combine(savePath, path); // #if UNITY_EDITOR_WIN // string copyToPath = savePath + "\\" + path; // #else // string copyToPath = savePath + "/" + path; // #endif string extension = System.IO.Path.GetExtension(path); if (setExclude.Contains(extension)) { continue; } if (supportedTypes[index] != "GameObject") { #if USE_RAW_MODE string projpath = "Assets" + path; WXRawResource rawResource = new WXRawResource(projpath); string ret_path = rawResource.Export(this); allRecursiveAssets.Add(ret_path); #else wxFileUtil.CopyFile(absolutePath, copyToPath); #endif } JSONObject fileInfo = new JSONObject(JSONObject.Type.OBJECT); // fileInfo.AddField("key", Path.GetFileNameWithoutExtension(filename)); string key = getResourcePath(path); if (setFiles.Contains(key)) { continue; } else { setFiles.Add(key); } fileInfo.AddField("key", key); fileInfo.AddField("name", "Assets" + path); data.Add(fileInfo); totalCount++; EditorUtility.DisplayProgressBar("原始资源导出", "", t++ / guids.Length); } jsonConfig.Add(category); } } #if USE_RAW_MODE string tempConfigFile = Path.Combine(Application.dataPath, "Resources.json"); wxFileUtil.SaveJsonFile(jsonConfig, tempConfigFile); string configpath = "Assets/Resources.json"; WXRawResource rawConfig = new WXRawResource(configpath); string ret_cfg_path = rawConfig.Export(this); allRecursiveAssets.Add(ret_cfg_path); File.Delete(tempConfigFile); #endif // string content = jsonConfig.ToString(); // ExportStore.AddTextFile(configpath, content, WXUtility.GetMD5FromString(content)); // List<string> useConfig = new List<string>(); // useConfig.Add(configpath); // ExportStore.AddResource(configpath, "raw", null, useConfig); // allRecursiveAssets.Add(configpath); ExportStore.GenerateResourcePackage( "WXResources", allRecursiveAssets ); EditorUtility.ClearProgressBar(); Debug.Log("导出成功,总共导出文件个数:" + totalCount); }