private static void ExportPlugins(UnityPlugin single = null) { var logger = new Bridge.Translator.Logging.Logger("plugins_export_logger", true, LoggerLevel.None, false, new MyLoggerWriter(), new Bridge.Translator.Logging.FileLoggerWriter()); var plugins = ConfigManager.configEntry.unityPluginConfig.unityPlugins; // 处理只转换一个插件的情况 if (single != null) { // if (single.pluginState == UnityPlugin.PluginState.stub) { // single.stubConfig.generateJSTemplate = true; // } plugins = new List <UnityPlugin>() { single }; } plugins .Where(p => p.enable) .ToList() .ForEach(plugin => { // clear temp RemoveTempCodeDir(); var bridgeOptions = new BridgeOptions(); if (plugin.pluginState == UnityPlugin.PluginState.convert) { plugin.convertedPath = new UnityPlugin.ConvertedPath(plugin); ConfigureBridgeOptionsForConvertPlugin(ref bridgeOptions, plugin); ProcessBridge(bridgeOptions, logger, // Pre Process (processor) => { // add plugin outside logger.Info("Add Plugin..."); if (single != null) { processor.Translator.Plugins.AddPlugin(new BridgePlugin(single.pluginName)); } else { processor.Translator.Plugins.AddPlugin(new BridgePlugin()); } logger.Info("Add Plugin...[done]"); // clean js output DirectoryUtil.DeleteDirectory(plugin.convertedPath.convertedJSPath); { // remove all dll2 var distDir = references["Bridge"].FullPath; Directory.EnumerateFiles(distDir, "*.dll2", SearchOption.AllDirectories) .ToList() .ForEach(f => { File.Delete(f); }); } { // copy all plugins dlls into references path var dlls = GetDepDlls(plugin); var distDir = references["Bridge"].FullPath; dlls.ForEach(dll => { var fileName = Path.GetFileNameWithoutExtension(dll); File.Copy(dll, Path.Combine(distDir, fileName + ".dll2"), true); }); } }, // Post Process (processor) => { // caching binding scripts var dir = build["Temp"]["bindings"]; var bindingScripts = Directory.EnumerateFiles(dir, "*.js", SearchOption.AllDirectories); var cacheDir = build["BindingsCache"].FullPath; if (!Directory.Exists(cacheDir)) { Directory.CreateDirectory(cacheDir); } foreach (var bs in bindingScripts) { var fileName = Path.GetFileName(bs); File.Copy(bs, Path.Combine(cacheDir, fileName), true); } // move files to plugin js output var tmpPath = build["Temp"].FullPath; var projDir = plugin.convertedPath.convertedJSPath; DirectoryUtil.CopyDirectory(tmpPath, projDir); DirectoryUtil.DeleteDirectory(tmpPath); // move dll to plugin dll output var projDllSrc = build["Output"][plugin.pluginName + ".dll"]; var projDllDist = plugin.convertedPath.convertedDLLPath; File.Copy(projDllSrc, projDllDist, true); Debug.Log("<" + plugin.pluginName + "> convertion finish."); } ); } else if (plugin.pluginState == UnityPlugin.PluginState.stub) { // generate cs stub if (plugin.stubConfig.generateStub) { plugin.stubPath = new UnityPlugin.StubPath(plugin); GenerateStubProc.GeneratePluginStub(plugin); Debug.Log("Generate Stub <" + plugin.pluginName + ">"); // 自动生成桩代码只需要一次 plugin.stubConfig.generateStub = false; } // generate js stub template if (plugin.stubConfig.generateJSTemplate) { ConfigureBridgeOptionsForStubPlugin(ref bridgeOptions, plugin); ProcessBridge(bridgeOptions, logger, // Pre Process (processor) => { // add plugin outside if (single != null) { processor.Translator.Plugins.AddPlugin(new BridgePlugin(single.pluginName + "-stub")); } else { processor.Translator.Plugins.AddPlugin(new BridgePlugin()); } // clean js output DirectoryUtil.DeleteDirectory(plugin.stubPath.stubJSPath); { // remove all dll2 var distDir = references["Bridge"].FullPath; Directory.EnumerateFiles(distDir, "*.dll2", SearchOption.AllDirectories) .ToList() .ForEach(f => { File.Delete(f); }); } { // copy unity stub dll var dll = UnityPluginUtil.GetUnityEngineStub().stubPath.stubDLLPath; var fileName = Path.GetFileNameWithoutExtension(dll); var distDir = references["Bridge"].FullPath; File.Copy(dll, Path.Combine(distDir, fileName + ".dll2"), true); } }, // Post Process (processor) => { // caching binding scripts var dir = build["Temp"]["bindings"]; var bindingScripts = Directory.EnumerateFiles(dir, "*.js", SearchOption.AllDirectories); var cacheDir = build["BindingsCache"].FullPath; if (!Directory.Exists(cacheDir)) { Directory.CreateDirectory(cacheDir); } foreach (var bs in bindingScripts) { var fileName = Path.GetFileName(bs); File.Copy(bs, Path.Combine(cacheDir, fileName), true); } if (single != null) { single.stubConfig.generateJSTemplate = false; } // move files to plugin js output var tmpPath = build["Temp"].FullPath; var stubJSDir = plugin.stubPath.stubJSPath; DirectoryUtil.CopyDirectory(tmpPath, stubJSDir); DirectoryUtil.DeleteDirectory(tmpPath); Debug.Log("<" + plugin.pluginName + "> stub template convertion finish."); } ); } } EditorUtility.DisplayProgressBar("Exporting", "...", 0.0f); }); }
private static void ExportCode() { // clear temp/cache RemoveProjectCodeDir(); RemoveTempCodeDir(); var logger = new Bridge.Translator.Logging.Logger("project_export_logger", true, LoggerLevel.None, false, new MyLoggerWriter(), new Bridge.Translator.Logging.FileLoggerWriter()); // var config = Config.Get(); var projectConfig = ConfigManager.configEntry.projectExportConfig; var pluginConfig = ConfigManager.configEntry.unityPluginConfig; var bridgeOptions = new BridgeOptions(); ConfigureBridgeOptionsForProject(ref bridgeOptions, projectConfig, pluginConfig); // ReferenceBuilder.Build(projectConfig, pluginConfig); ProcessBridge(bridgeOptions, logger, // Pre Process (processor) => { // add plugin outside logger.Info("Add Plugin..."); processor.Translator.Plugins.AddPlugin(new BridgePlugin()); logger.Info("Add Plugin...[done]"); // remove all dll2 var distDir = references["Bridge"].FullPath; Directory.EnumerateFiles(distDir, "*.dll2", SearchOption.AllDirectories) .ToList() .ForEach(f => { File.Delete(f); }); // copy all plugins dlls into references path var dlls = GetDepDlls(pluginConfig); dlls.ForEach(dll => { var fileName = Path.GetFileNameWithoutExtension(dll); // Debug.Log(fileName); File.Copy(dll, Path.Combine(distDir, fileName + ".dll2"), true); }); }, // Post Process (processor) => { // caching binding scripts var dir = build["Temp"]["bindings"]; var bindingScripts = Directory.EnumerateFiles(dir, "*.js", SearchOption.AllDirectories); var cacheDir = build["BindingsCache"].FullPath; if (!Directory.Exists(cacheDir)) { Directory.CreateDirectory(cacheDir); } foreach (var bs in bindingScripts) { var fileName = Path.GetFileName(bs); File.Copy(bs, Path.Combine(cacheDir, fileName), true); } // move Temp/ files to Project/ var tmpPath = build["Temp"].FullPath; var projDir = build["Project"].FullPath; DirectoryUtil.CopyDirectory(tmpPath, projDir); DirectoryUtil.DeleteDirectory(tmpPath); Debug.Log("Project code convertion finish."); } ); }