Пример #1
0
        LuaTable LoadLuaTable(string path)
        {
            string[] textLine = EditorUtils.GetFileTextLine(path);
            LuaTable lt       = new LuaTable();

            if (textLine != null && textLine.Length > 0)
            {
                lt.fromTextLine(textLine);
                Debug.Log("Load Lua Table -- " + lt.ToString());
                List <string> delList = new List <string>();
                foreach (var viewName in lt.HashTable.Keys)
                {
                    string modulePath = Application.dataPath + "/" + ModulesDir + lt.GetString(viewName, "module");
                    string viewPath   = modulePath + ToLuaGenerater.Folder2Directory(LuaFolder.View) + lt.GetString(viewName, "name") + "Mdr.lua";
                    if (!Directory.Exists(modulePath) || !File.Exists(viewPath))
                    {
                        Debug.Log(viewPath);
                        if (!delList.Contains(viewName))
                        {
                            delList.Add(viewName);
                        }
                    }
                }
                foreach (var viewName in delList)
                {
                    lt.HashTable.Remove(viewName);
                }
            }
            return(lt);
        }
Пример #2
0
        //加载所有模块
        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);
            }
        }
Пример #3
0
        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;
            }
        }