Beispiel #1
0
//         [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();
        }
Beispiel #2
0
        static public void OnForceImpotChangedExcel()
        {
            //判断是否导入设置
            if (BDEditorApplication.BDFrameworkEditorSetting.BuildSqlSetting.IsForceImportChangedExcelOnWillEnterPlaymode)
            {
                var(changedExcelList, newEcxcelInfoMap) = ExcelEditorTools.GetChangedExcels();
                if (changedExcelList.Count > 0)
                {
                    BDebug.Log("-----------------强制导入修改的excel文件.begin-----------------", "red");

                    SqliteLoder.LoadLocalDBOnEditor(Application.streamingAssetsPath, BApplication.RuntimePlatform);
                    {
                        //开始导入
                        foreach (var excel in changedExcelList)
                        {
                            var path = AssetDatabase.GUIDToAssetPath(excel);
                            Excel2SQLiteTools.Excel2SQLite(path, DBType.Local);
                        }
                    }
                    SqliteLoder.Close();
                    BDebug.Log("-----------------强制导入修改的excel文件.end-----------------", "red");
                }
                //保存配置
                ExcelEditorTools.SaveExcelCacheInfo(newEcxcelInfoMap);
            }
        }
        /// <summary>
        /// 重写
        /// </summary>
        new public void Show()
        {
            //计算hash
            var(hash, hashmap) = ExcelEditorTools.GetExcelsHash();
            Debug.Log(hash);
            Debug.Log("表格hash预览:" + JsonMapper.ToJson(hashmap, true));
            // //获取差异文件
            // var changeExcelList = ExcelEditorTools.GetChangedExcels();
            //
            // //保存
            // if (changeExcelList.Count > 0)
            // {
            //
            //     for (int i = 0; i < changeExcelList.Count; i++)
            //     {
            //         changeExcelList[i] = AssetDatabase.GUIDToAssetPath(changeExcelList[i]);
            //     }
            //
            //     Debug.Log("变动的Excel文件:" + JsonMapper.ToJson(changeExcelList, true));
            //     ExcelEditorTools.SaveExcelCacheInfo(hashmap);
            // }
            // else
            // {
            //     Debug.Log("无变动的文件:" + JsonMapper.ToJson(changeExcelList, true));
            // }

            //显示
            base.Show();
        }
Beispiel #4
0
        /// <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完成!");
        }