private void BuildReferencesDirectory(bool exist) { var references = DirectoryBuilder.RegisterDirectory("references", new DirectoryStructure("References~")); references.AddReadme("## 存放需用用到的资源"); references.AddSubDirectory("Adaptor", "## 存放代码导出用到的辅助脚本"); references.AddSubDirectory("Bridge", "## 存放代码导出用到的DLL库"); if (!exist) { // Debug.Log("not exist, move file"); var dist = new DirectoryInfo(Path.Combine(Application.dataPath, "__wx__tmp__res~", "Bridge")); references["Bridge"]["Bridge.dll"] = Path.Combine(dist.FullName, "Bridge.dll"); references["Bridge"]["Retyped.Core.dll"] = Path.Combine(dist.FullName, "Retyped.Core.dll"); references["Bridge"]["Retyped.es5.dll"] = Path.Combine(dist.FullName, "Retyped.es5.dll"); references["Adaptor"]["minigame-adaptor-config.js.lib"] = Path.Combine(dist.FullName, "minigame-adaptor-config.js.lib"); references["Adaptor"]["minigame-adaptor-util.js.lib"] = Path.Combine(dist.FullName, "minigame-adaptor-util.js.lib"); references["Adaptor"]["minigame-adaptor.js.lib"] = Path.Combine(dist.FullName, "minigame-adaptor.js.lib"); references["Adaptor"]["weapp-adapter.js.lib"] = Path.Combine(dist.FullName, "weapp-adapter.js.lib"); } references.BuildDirectory(); }
static BridgeExport() { references = DirectoryBuilder.RegisterDirectory("references", new DirectoryStructure("References~")); build = DirectoryBuilder.RegisterDirectory("build", new DirectoryStructure("Build~")); configs = DirectoryBuilder.RegisterDirectory("configs", new DirectoryStructure("Configs")); TMP_BINDING_CACHE = build["BindingsCache"].FullPath; TMP_CODE_PATH = build["Temp"].FullPath; PROJECT_CODE_PATH = build["Project"].FullPath; }
static DirectoryUtil() { configs = DirectoryBuilder.RegisterDirectory("configs", new DirectoryStructure("Configs")); configs.AddReadme("## 存放配置文件"); configs.AddSubDirectory("ScriptableObject", "## 存放ScriptableObject类型的配置文件"); configs.AddSubDirectory("Text", "## 存放文本类型的配置文件"); configs.BuildDirectory(); }
private void BuildDependencyDirectory(bool exist) { var build = DirectoryBuilder.RegisterDirectory("dependency", new DirectoryStructure("Dependency~")); build.AddReadme("## 存放依赖分析结果"); build.AddSubDirectory("Output", "## Output"); build.BuildDirectory(); }
private static void GeneratePluginStubDLL(UnityPlugin config) { if (!config.enable) { return; } if (references == null) { references = DirectoryBuilder.RegisterDirectory("references", new DirectoryStructure("References~")); } var sources = new List <string>() { config.stubPath.stubCSPath }; // Add refCS stub file var refCS = config.stubPath.stubRefCSPath; if (refCS != null && File.Exists(refCS)) { sources.Add(refCS); } var os = File.Create(config.stubPath.stubDLLPath); // var refs = UnityPluginUtil.GetLib(config, true, true); var refs = new List <string>() { references["Bridge"]["Bridge.dll"], UnityPluginUtil.GetUnityEngineStub().stubPath.stubDLLPath }; if (refs == null || refs.Count == 0) { return; } EmitResult result; try { result = DLLProc.BuildDLL(config.pluginName + "-stub", os, sources, config.defineMacros, refs, true); } finally { os.Close(); } if (result == null || !result.Success) { throw new Exception(); } }
private void BuildBuildDirectory(bool exist) { var build = DirectoryBuilder.RegisterDirectory("build", new DirectoryStructure("Build~")); build.AddReadme("## 存放代码转换产生的中间文件"); build.AddSubDirectory("Output", "## Output"); build.AddSubDirectory("Plugins", "## Plugins"); build.AddSubDirectory("Project", "## Project"); build.AddSubDirectory("Temp", "## Temp"); build.AddSubDirectory("BindingsCache", "## binding文件缓存"); build.BuildDirectory(); }
public static string GetModelToolPath() { string toolDir = ""; WXConfig.commons = DirectoryBuilder.RegisterDirectory("commons", new DirectoryStructure("Common")); if (Application.platform == RuntimePlatform.WindowsEditor) { toolDir = commons["Tools"].GetFilePath("model.exe"); } else if (Application.platform == RuntimePlatform.OSXEditor) { toolDir = commons["Tools"].GetFilePath("Model_Mac"); } return(toolDir); }
private void BuildConfigsDirectory(bool exist) { var configs = DirectoryBuilder.RegisterDirectory("configs", new DirectoryStructure("Configs")); configs.AddReadme("## 存放配置文件"); configs.AddSubDirectory("ScriptableObject", "## 存放ScriptableObject类型的配置文件"); configs.AddSubDirectory("Text", "## 存放文本类型的配置文件"); if (!exist) { // Debug.Log("not exist, move file"); var dist = new DirectoryInfo(Path.Combine(Application.dataPath, "__wx__tmp__res~", "Bridge")); configs["Text"]["bridge.json"] = Path.Combine(dist.FullName, "bridge.json"); configs["Text"]["BridgeTypes.txt"] = Path.Combine(dist.FullName, "BridgeTypes.txt"); } configs.BuildDirectory(); }
public static void Output(string fileName, string content) { var outoutDir = DirectoryBuilder.GetDirectory("dependency")["Output"].FullPath; var outputPath = Path.Combine(outoutDir, fileName); { var info = new DirectoryInfo(outoutDir); if (!info.Exists) { info.Create(); } } { var info = new FileInfo(outputPath); if (info.Exists) { info.Delete(); } } File.WriteAllText(outputPath, content); }
/// <summary> /// 判断资源文件是否存在,返回False为任意一个文件不存在 /// </summary> /// <returns>Boolean</returns> private bool Precheck() { // DirectoryStructure Init if (build == null) { build = DirectoryBuilder.RegisterDirectory("build", new DirectoryStructure("Build~")); } if (references == null) { references = DirectoryBuilder.RegisterDirectory("references", new DirectoryStructure("References~")); } if (configs == null) { configs = DirectoryBuilder.RegisterDirectory("configs", new DirectoryStructure("Configs")); } // Check Files return(textResList.TrueForAll(res => CheckFileExist(configs, "Text", res)) && bridgeResList.TrueForAll(res => CheckFileExist(references, "Bridge", res)) && adaptorResList.TrueForAll(res => CheckFileExist(references, "Adaptor", res))); }
private void OnEnable() { if (ConfigManager.configEntry == null) { ConfigManager.Init(); } unityPlugins = EditorHelper.CreateReorderableList("unityPlugins", "工程插件列表", serializedObject); // unityPlugins = new ReorderableList( // serializedObject, // serializedObject.FindProperty("unityPlugins"), // false, true, true, true // ); // unityPlugins.drawElementCallback += (Rect rect, int index, bool isActive, bool isFocused) => // { // var element = unityPlugins.serializedProperty.GetArrayElementAtIndex(index); // rect.y += 4; // var width = EditorGUIUtility.currentViewWidth - 200; // var pluginDrawRect = new Rect(rect.x, rect.y, width, EditorGUIUtility.singleLineHeight); // SerializedProperty plugin = element; // if (plugin.objectReferenceValue != null) // { // plugin.objectReferenceValue = null; // } // EditorGUI.PropertyField( // pluginDrawRect, // plugin, // GUIContent.none // ); // // EditorGUI.PropertyField( // // enableDrawRect, // // element.FindPropertyRelative("enable"), // // new GUIContent("Enable") // // ); // }; unityPlugins.onAddCallback += (ReorderableList list) => { // add existed plugins var pluginConfig = target as UnityPluginConfig; if (pluginConfig.unityPlugins != null && pluginConfig.unityPlugins.Count == 0) { var configs = DirectoryBuilder.RegisterDirectory("config", new DirectoryStructure("Configs")); var _path = configs["ScriptableObject"].GetFilePath("bridge/plugins").PathToAssets(); // Debug.Log(_path); var pluginsGUID = AssetDatabase.FindAssets("t:UnityPlugin", new[] { _path }); Debug.Log("No plugins in List, add " + pluginsGUID.Length); if (pluginsGUID != null) { foreach (string plugin in pluginsGUID) { var soPath = AssetDatabase.GUIDToAssetPath(plugin); var so = AssetDatabase.LoadAssetAtPath <UnityPlugin>(soPath); pluginConfig.unityPlugins.Add(so); } } } // Debug.Log("!!!"); listView = (PluginListView)EditorWindow.GetWindow(typeof(PluginListView), true, "快速选择插件文件夹", true); listView.IterateAllDirectories(); listView.Show(true); listView.onAddCallback = (UnityPlugin plugin) => { Debug.Log("Add Plugin : " + plugin.pluginName); pluginConfig.unityPlugins.Add(plugin); EditorUtility.SetDirty(pluginConfig); AssetDatabase.SaveAssets(); // TODO: Repaint }; // Debug.Log("setdirty"); EditorUtility.SetDirty(pluginConfig); AssetDatabase.SaveAssets(); }; }
public static void GeneUnityStub(bool overwrite = true) { var unity = UnityPluginUtil.GetUnityEngineStub(); if (!overwrite && File.Exists(unity.stubPath.stubCSPath)) { Debug.LogWarning("UnityEngine Stub Exist."); return; } if (unity.stubConfig.generateStub) { // UnityStubBuilder.Build(unity.stubPath.stubCSPath); // 这里改用反射 // UnityStubBuilder.cs 需要被单独作为c#源文件放出,编DLL时不能耦合 // Type.GetType("WeChat.UnityStubBuilder").GetMethod("Build").Invoke(null, new object[] { unity.stubPath.stubCSPath }); // 这里改用回调,DLL里调用反射拿不到C#源文件里定义的类,有空再查 if (genUnityStubCallback != null) { genUnityStubCallback.Invoke(unity.stubPath.stubCSPath); } } // header var allRefContent = string.Format(topHeader, unity.pluginName); string content = ""; using (StreamReader sr = new StreamReader(unity.stubPath.stubCSPath)) { content = sr.ReadToEnd(); } if (content == null || content == "" || content.Length == 0) { return; } using (var sw = new StreamWriter(unity.stubPath.stubCSPath, false)) { sw.Write(allRefContent); sw.Write(content); } var sources = new List <string>() { unity.stubPath.stubCSPath }; var dir = new DirectoryInfo(Path.GetDirectoryName(unity.stubPath.stubDLLPath)); if (!dir.Exists) { dir.Create(); } var os = File.Create(unity.stubPath.stubDLLPath); if (references == null) { references = DirectoryBuilder.RegisterDirectory("references", new DirectoryStructure("References~")); } var refs = new List <string>() { references["Bridge"]["Bridge.dll"] }; EmitResult result; try { result = DLLProc.BuildDLL("UnityEngine-stub", os, sources, unity.defineMacros, refs, true); } finally { os.Close(); } if (result == null || !result.Success) { throw new Exception(); } Debug.Log("Generate Stub <UnityEngine>"); }
public static string OutputPath(string fileName) { return(DirectoryBuilder.GetDirectory("dependency")["Output"].FullPath); }
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"); }
static PathUtil() { build = DirectoryBuilder.RegisterDirectory("build", new DirectoryStructure("Build~")); }