//加载所有模块 void LoadAllModules() { string modulesRootDir = Path.Combine(Application.dataPath, ModulesDir); if (!Directory.Exists(modulesRootDir)) { return; } string[] moduleDirs = Directory.GetDirectories(modulesRootDir); moduleInfoList = new List <LuaModuleInfo>(); for (int i = 0; i < moduleDirs.Length; i++) { string moduleDirPath = moduleDirs[i]; //模块目录路径 LuaModuleInfo moduleInfo = new LuaModuleInfo(Path.GetFileName(moduleDirs[i])); moduleInfo.moduleDirPath = moduleDirPath; //模块目录路径 // if (moduleDirPath.IndexOf("Common") != -1) // continue; moduleInfo.viewDirPath = moduleDirPath + ToLuaGenerater.Folder2Directory(LuaFolder.View); moduleInfo.modelDirPath = moduleDirPath + ToLuaGenerater.Folder2Directory(LuaFolder.Model); moduleInfo.serviceDirPath = moduleDirPath + ToLuaGenerater.Folder2Directory(LuaFolder.Service); moduleInfo.voDirPath = moduleDirPath + ToLuaGenerater.Folder2Directory(LuaFolder.Vo); moduleInfo.controllerDirPath = moduleDirPath + ToLuaGenerater.Folder2Directory(LuaFolder.Ctrl); //Views if (!Directory.Exists(moduleDirPath)) { continue; } if (!Directory.Exists(moduleInfo.viewDirPath)) { continue; } string[] mdrFiles = Directory.GetFiles(moduleInfo.viewDirPath, "*.lua"); for (int j = 0; j < mdrFiles.Length; j++) { string mdrFilePath = mdrFiles[j]; string mdrName = Path.GetFileNameWithoutExtension(mdrFilePath); if (mdrName.IndexOf("Mdr") == -1) { continue; } mdrName = mdrName.Replace("Mdr", ""); LuaViewInfo viewInfo = new LuaViewInfo(mdrName); viewInfo.viewName = mdrName; viewInfo.viewDirPath = moduleInfo.viewDirPath; viewInfo.moduleName = moduleInfo.moduleName; if (luaTable.HasTable(mdrName))//已经存在配置 { luaTable.SetHashTable(viewInfo.viewName, "module", moduleInfo.moduleName); viewInfo.prefabUrl = luaTable.GetString(mdrName, "prefab"); } moduleInfo.viewList.Add(viewInfo); } //Vo moduleInfo.voList = RefreshSingleFile(moduleInfo, moduleInfo.voDirPath); moduleInfo.ctrlList = RefreshSingleFile(moduleInfo, moduleInfo.controllerDirPath); moduleInfoList.Add(moduleInfo); } }
void DrawFoldout(LuaModuleInfo moduleInfo) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginHorizontal(GUILayout.Width(this.position.width * (1 - 0.618f))); moduleInfo.isOpen = EditorGUILayout.Foldout(moduleInfo.isOpen, moduleInfo.moduleName); EditorGUILayout.LabelField(new GUIContent(moduleInfo.moduleDirPath.Replace(Application.dataPath, ""))); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); // ResUtils.ColorLabel(Title_Error, rd.errorNum.ToString(), rd.errorNum == 0 ? 0 : 2); // ResUtils.ColorLabel(Title_Warning, rd.warnNum.ToString(), rd.warnNum < 1 ? 0 : 1); // ResUtils.ColorLabel(Title_Repeat, rd.resources.Count.ToString(), rd.resources.Count <= 1 ? 0 : 2); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndHorizontal(); }
List <string> RefreshSingleFile(LuaModuleInfo moduleInfo, string dirPath) { List <string> fileList = new List <string>(); if (Directory.Exists(dirPath)) { string[] files = Directory.GetFiles(dirPath, "*.lua"); for (int j = 0; j < files.Length; j++) { fileList.Add(Path.GetFileNameWithoutExtension(files[j])); } } return(fileList); }
void EditFolder(LuaModuleInfo moduleInfo, LuaFolder folder) { string folderPath = moduleInfo.moduleDirPath + ToLuaGenerater.Folder2Directory(folder); LuaFileStatus status = ToLuaGenerater.GetFileStatus(moduleInfo.moduleDirPath, folder); switch (status) { case LuaFileStatus.Nothing: if (GUILayout.Button("生成 " + folder + " 文件夹")) { ToLuaGenerater.GeneratedFolder(folderPath); } break; case LuaFileStatus.Folder_Only: if (folder == LuaFolder.Vo) { AddVoFile(moduleInfo); } else if (folder == LuaFolder.Controller) { AddCommandFile(moduleInfo); } else if (GUILayout.Button("生成 " + folder + ".lua 文件")) { ToLuaGenerater.GeneratedLuaFile(moduleInfo.moduleDirPath, moduleInfo.moduleName, moduleInfo.moduleName, folder); } break; case LuaFileStatus.Folder_And_LuaFile: if (folder == LuaFolder.Vo) { AddVoFile(moduleInfo); } else if (folder == LuaFolder.Controller) { AddCommandFile(moduleInfo); } else { EditorGUILayout.LabelField(moduleInfo.moduleName + folder + ".lua 文件已经生成"); } break; } }
void GeneratedMvcFiles() { StringBuilder mdrSb = new StringBuilder(); StringBuilder modelSb = new StringBuilder(); StringBuilder serviceSb = new StringBuilder(); for (int i = 0; i < moduleInfoList.Count; i++) { LuaModuleInfo moduleInfo = moduleInfoList[i]; if (Directory.Exists(moduleInfo.viewDirPath)) { string[] mdrFiles = Directory.GetFiles(moduleInfo.viewDirPath, "*Mdr.lua"); for (int j = 0; j < mdrFiles.Length; j++) { mdrSb.AppendLine( ToLuaGenerater.GetMdrLuaLine(mdrFiles[j], moduleInfo.moduleName, LuaFolder.Mdr)); } } if (Directory.Exists(moduleInfo.modelDirPath)) { string[] modelFiles = Directory.GetFiles(moduleInfo.modelDirPath, "*Model.lua"); for (int j = 0; j < modelFiles.Length; j++) { modelSb.AppendLine(ToLuaGenerater.GetSingletonLuaLine(modelFiles[j], LuaFolder.Model)); } } if (Directory.Exists(moduleInfo.serviceDirPath)) { string[] serviceFiles = Directory.GetFiles(moduleInfo.serviceDirPath, "*Service.lua"); for (int j = 0; j < serviceFiles.Length; j++) { serviceSb.AppendLine(ToLuaGenerater.GetSingletonLuaLine(serviceFiles[j], LuaFolder.Service)); } } } ToLuaGenerater.GeneratedTODOLua(MediatorContextPath, mdrSb); ToLuaGenerater.GeneratedTODOLua(ModelContextPath, modelSb); ToLuaGenerater.GeneratedTODOLua(ServiceContextPath, serviceSb); }
void AddCommandFile(LuaModuleInfo moduleInfo) { EditorGUILayout.BeginHorizontal(); newCommandName = EditorGUILayout.TextField("新 Controller 名称:", newCommandName); if (GUILayout.Button("新增", endButtonWidth)) { if (!ToLuaGenerater.FileNameValid(newCommandName, this)) { return; } if (newCommandName.EndsWith(LuaFolder.Controller.ToString())) { newCommandName = newCommandName.Substring(0, newCommandName.Length - 3); } ToLuaGenerater.GeneratedLuaFile(moduleInfo.moduleDirPath, moduleInfo.moduleName, newCommandName, LuaFolder.Controller); moduleInfo.ctrlList = RefreshSingleFile(moduleInfo, moduleInfo.controllerDirPath); newCommandName = ""; } EditorGUILayout.EndHorizontal(); }
void AddVoFile(LuaModuleInfo moduleInfo) { EditorGUILayout.BeginHorizontal(); newVoName = EditorGUILayout.TextField("新Vo 名称:", newVoName); if (GUILayout.Button("新增", endButtonWidth)) { if (!ToLuaGenerater.FileNameValid(newVoName, this)) { return; } if (newVoName.EndsWith("Vo")) { newVoName = newVoName.Substring(0, newVoName.Length - 2); } ToLuaGenerater.GeneratedLuaFile(moduleInfo.moduleDirPath, moduleInfo.moduleName, newVoName, LuaFolder.Vo); moduleInfo.voList = RefreshSingleFile(moduleInfo, moduleInfo.voDirPath); newVoName = ""; } EditorGUILayout.EndHorizontal(); }
void EditModulelist() { for (int i = 0; i < moduleInfoList.Count; i++) { LuaModuleInfo moduleInfo = moduleInfoList[i]; if (moduleInfo.isOpen) { DrawFoldout(moduleInfo); EditorGUILayout.LabelField("模块:", moduleInfo.moduleName); EditorGUI.indentLevel++; EditorGUILayout.LabelField("Views:"); EditorGUI.indentLevel++; for (int j = 0; j < moduleInfo.viewList.Count; j++) { EditorGUI.indentLevel++; LuaViewInfo viewInfo = moduleInfo.viewList[j]; if (luaTable.HasTable(viewInfo.viewName)) { //已经存在配置 Dictionary <string, object> table = luaTable.GetTable(viewInfo.viewName); EditorGUILayout.LabelField("View name:", viewInfo.viewName); if (string.IsNullOrEmpty(viewInfo.prefabUrl)) { viewInfo.prefabUrl = luaTable.GetString(viewInfo.viewName, "prefab"); } oldString = viewInfo.prefabUrl; FetchPrefabUrl(viewInfo); if (oldString != viewInfo.prefabUrl) { luaTable.SetHashTable(viewInfo.viewName, "prefab", viewInfo.prefabUrl); } } else { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("搜索到新的View:" + viewInfo.viewName + "是否新建?"); if (GUILayout.Button("新建", endButtonWidth)) { luaTable.SetTable(viewInfo.viewName); luaTable.SetHashTable(viewInfo.viewName, "module", moduleInfo.moduleName); luaTable.SetHashTable(viewInfo.viewName, "name", viewInfo.viewName); } EditorGUILayout.EndHorizontal(); } EditorGUILayout.BeginHorizontal(); { LuaFileStatus status = ToLuaGenerater.GetFileStatus(moduleInfo.moduleDirPath, LuaFolder.Mdr, viewInfo.viewName); if (status == LuaFileStatus.Folder_Only || status == LuaFileStatus.Folder_And_LuaFile) { EditorGUILayout.LabelField("Mdr文件:"); if (GUILayout.Button("生成 " + viewInfo.viewName + " 的 Mediator 文件")) { ToLuaGenerater.GeneratedLuaFile(moduleInfo.moduleDirPath, moduleInfo.moduleName, viewInfo.viewName, LuaFolder.Mdr); } } else if (status == LuaFileStatus.Folder_And_TagLuaFile) { EditorGUILayout.LabelField("Mdr文件:", viewInfo.viewName + LuaFolder.Mdr + ".lua 文件已经生成"); } else { EditorGUILayout.LabelField("Mdr文件:", status.ToString()); } } EditorGUILayout.EndHorizontal(); EditorGUI.indentLevel--; EditorGUILayout.Space(); } EditorGUI.indentLevel--; //Vos EditorGUI.indentLevel++; { EditorGUILayout.LabelField("Value Objects:"); if (moduleInfo.voList.Count > 0) { for (int j = 0; j < moduleInfo.voList.Count; j++) { EditorGUILayout.LabelField((j + 1).ToString(), moduleInfo.voList[j] + ".lua"); } } EditFolder(moduleInfo, LuaFolder.Vo); EditorGUILayout.LabelField("Controllers:"); if (moduleInfo.ctrlList.Count > 0) { for (int j = 0; j < moduleInfo.ctrlList.Count; j++) { EditorGUILayout.LabelField((j + 1).ToString(), moduleInfo.ctrlList[j] + ".lua"); } } EditFolder(moduleInfo, LuaFolder.Controller); } EditorGUI.indentLevel--; EditorGUILayout.Space(); EditFolder(moduleInfo, LuaFolder.Model); EditFolder(moduleInfo, LuaFolder.Service); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); moduleInfo.newViewMdrName = EditorGUILayout.TextField("新View 名称:", moduleInfo.newViewMdrName); if (GUILayout.Button("新增", endButtonWidth)) { if (!ToLuaGenerater.FileNameValid(moduleInfo.newViewMdrName, this)) { return; } LuaViewInfo viewInfo = new LuaViewInfo(moduleInfo.newViewMdrName); viewInfo.viewName = moduleInfo.newViewMdrName; viewInfo.viewDirPath = moduleInfo.viewDirPath; luaTable.SetTable(viewInfo.viewName); luaTable.SetHashTable(viewInfo.viewName, "name", viewInfo.viewName); luaTable.SetHashTable(viewInfo.viewName, "module", moduleInfo.moduleName); moduleInfo.viewList.Add(viewInfo); moduleInfo.newViewMdrName = ""; } EditorGUILayout.EndHorizontal(); EditorUtils.DrawHorizontalSplitter(); EditorGUI.indentLevel--; } else { DrawFoldout(moduleInfo); } } }