// [MenuItem("BDFrameWork工具箱/3.表格/表格->生成Class[策划目录]", false, (int) BDEditorGlobalMenuItemOrderEnum.BuildPackage_Table_Table2Class)] // public static void Gen2() // { // var ret = EditorUtility.DisplayDialog("提示", @" // Excel格式如下: // 1.第一行为备注 // 2.第二行可以自定义字段类型,如没检测到则自动分析字段类型 // 3.所有表格字段名必须以Id开始,即第二或第三行首列必须是Id", "OK"); // if (ret) // { // if (Directory.Exists(OldGameResourceTableCodePath)) // { // Directory.Delete(OldGameResourceTableCodePath, true); // } // // GenCode(GameResourceTableCodePath); // } // } /// <summary> /// 生成代码 /// </summary> public static void GenCode(string outputPath) { var xlslFiles = ExcelEditorTools.GetAllExcelFiles(); // if (xlslFiles.Count == 0) { EditorUtility.DisplayDialog("提示", "未发现xlsx文件,请注意不是xls", "确定"); return; } //同名文件判断 var fnlist = xlslFiles.Select((s) => Path.GetFileName(s).ToLower()).ToList(); foreach (var fn in fnlist) { var rets = fnlist.FindAll((f) => f == fn); if (rets.Count > 1) { EditorUtility.DisplayDialog("提示", "Sqlite表名 字段名不区分大小写,请处理重名exel! ->" + fn, "OK"); return; } } //导出excel foreach (var f in xlslFiles) { GenClassByExcel(outputPath, f, "Local"); GenClassByExcel(outputPath, f, "Server"); } EditorUtility.DisplayDialog("提示", "生成完成!", "确定"); AssetDatabase.Refresh(); }
/// <summary> /// 生成sqlite /// 默认导出到当前平台目录下 /// </summary> /// <param name="ouptputPath">自定义路径</param> public static void AllExcel2SQLite(string ouptputPath, RuntimePlatform platform, DBType dbType = DBType.Local) { //触发bd环境周期 BDFrameworkPipelineHelper.OnBeginBuildSqlite(); var xlslFiles = ExcelEditorTools.GetAllExcelFiles(); switch (dbType) { case DBType.Local: SqliteLoder.LoadLocalDBOnEditor(ouptputPath, platform); break; case DBType.Server: SqliteLoder.LoadServerDBOnEditor(ouptputPath, platform); break; } //清空表 SqliteHelper.DB.Connection.DropTable <ImportExcelLog>(); { foreach (var f in xlslFiles) { try { Excel2SQLite(f, dbType); } catch (Exception e) { Debug.LogError(e); Debug.LogError("导表失败:" + f); EditorUtility.ClearProgressBar(); } } } SqliteLoder.Close(); // EditorUtility.ClearProgressBar(); //触发bd环境周期 BDFrameworkPipelineHelper.OnEndBuildSqlite(ouptputPath); GlobalAssetsHelper.GenBasePackageAssetBuildInfo(ouptputPath, platform); Debug.Log("导出Sqlite完成!"); }