Browse Source

拆分表结构

zhaoyang 2 years ago
parent
commit
302b451c0e

+ 1 - 15
GameClient/Assets/Editor/Excel/CodeBuilder.cs

@@ -415,7 +415,7 @@ namespace GFGEditor
 
                 }
             }
-            if (configArrayName == nameof(HeadAniCfgArray) && !string.IsNullOrEmpty(headAniKey) && !string.IsNullOrEmpty(headAniValue))
+            if (!_headAniDicByName.ContainsKey(headAniKey) && configArrayName == nameof(HeadAniCfgArray) && !string.IsNullOrEmpty(headAniKey) && !string.IsNullOrEmpty(headAniValue))
             {
                 _headAniDicByName.Add(headAniKey, headAniValue);
             }
@@ -497,11 +497,8 @@ namespace GFGEditor
         {
             Dictionary<string, List<string>> _twoDimensionalDic = new Dictionary<string, List<string>>();
             string value = "";
-            // foreach (var i in _allIndexs)
-            // {
             for (int i = index - 1; i < _allIndexs.Count; i++)
             {
-                // int _index = i - 1;
                 string _name = _allNames[i];
                 string[] _names = _name.Split('#');
                 string _type = _allTypes[i];
@@ -550,17 +547,6 @@ namespace GFGEditor
                 List<string> _values = new List<string>();
                 foreach (string key in _twoDimensionalDic.Keys)
                 {
-                    // if (!_twoDimensionalDic[key].ContainsKey(0)) continue;
-                    // string _value0 = _twoDimensionalDic[key][0];
-                    // if (!_twoDimensionalDic[key].ContainsKey(1))
-                    // {
-                    //     _values.Add(_value0);
-                    // }
-                    // else
-                    // {
-                    //     string str = string.Format("{0}*{1}", _value0, _twoDimensionalDic[key][1]);
-                    //     _values.Add(str);
-                    // }
                     _values.Add(string.Join("*", _twoDimensionalDic[key]));
                 }
                 value = string.Join(";", _values);

+ 4 - 0
GameClient/Assets/Editor/Excel/ExcelConfig.cs

@@ -9,6 +9,10 @@ namespace GFGEditor
         /// 存放excel表文件夹的的路径
         /// </summary>
         public const string excelsFolderPath = "../../../gfg/tools/Config";
+        /// <summary>
+        /// 存放临时excel表文件夹的的路径
+        /// </summary>
+        public const string excelsCacheFolderPath = "../../../gfg/tools/Config/CacheConfig/";
 
         /// <summary>
         /// 共享库中存放sqlite文件的的路径

+ 162 - 1
GameClient/Assets/Editor/Excel/ExcelReader.cs

@@ -4,6 +4,7 @@ using UnityEngine;
 using System.Data;
 using GFGEditor;
 using OfficeOpenXml;
+using System;
 
 namespace GFGEditor
 {
@@ -13,7 +14,7 @@ namespace GFGEditor
 
         public static void ReadExcel(RowCollectionHandler rowCollectionHandler)
         {
-            string[] files = Directory.GetFiles(ExcelConfig.excelsFolderPath);
+            string[] files = Directory.GetFiles(ExcelConfig.excelsCacheFolderPath);
             int totalCount = files.Length;
             string strCfgArrayDispose = "";
             string strCfgArrayInit = "";
@@ -96,5 +97,165 @@ namespace GFGEditor
             return configManagerName;
         }
 
+
+        public static void WriteExcle()
+        {
+            DeleteExcle();
+            string[] files = Directory.GetFiles(ExcelConfig.excelsFolderPath);
+            int totalCount = files.Length;
+            for (int i = 0; i < totalCount; i++)
+            {
+                string filePath = files[i];
+                string fileName = Path.GetFileNameWithoutExtension(filePath);
+                if (!fileName.Contains("~"))
+                {
+                    string newPath = ExcelConfig.excelsCacheFolderPath + fileName + ".xlsx";
+                    Stream newStream = new FileStream(newPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
+                    ExcelPackage newExcelPackage = new ExcelPackage(newStream);
+                    ExcelWorksheets newWorksheets = newExcelPackage.Workbook.Worksheets;
+
+                    Stream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
+                    ExcelPackage excelPackage = new ExcelPackage(stream);
+                    ExcelWorksheets Worksheets = excelPackage.Workbook.Worksheets;
+                    for (int j = 1; j <= Worksheets.Count; j++)
+                    {
+                        ExcelWorksheet worksheet = Worksheets[j];
+                        string[] names = worksheet.Name.Split('_');
+                        if (names.Length < 2) continue;
+                        ExcelWorksheet newWorksheet = null;
+                        for (int k = 1; k <= newWorksheets.Count; k++)
+                        {
+                            string[] newNames = newWorksheets[k].Name.Split('_');
+                            if (names.Length < 2 || names.Length != newNames.Length) continue;
+
+                            for (int h = 1; h < names.Length; h++)
+                            {
+                                if (newNames[h] == names[h])
+                                {
+                                    newWorksheet = newWorksheets[k];
+                                }
+                                else
+                                {
+                                    newWorksheet = null;
+                                    break;
+                                }
+                            }
+                        }
+                        if (newWorksheet == null)
+                        {
+                            newWorksheets.Add(worksheet.Name);
+                            newWorksheet = newWorksheets[newWorksheets.Count];
+                        }
+                        WriteTitle(newWorksheet, worksheet);
+                        // Debug.Log(worksheet.Name + "写入完成");
+                    }
+                    newExcelPackage.Save();
+                    excelPackage.Save();
+                    newStream.Close();
+                    stream.Close();
+                    newStream.Dispose();
+                    stream.Dispose();
+                    Debug.Log(fileName + "写入完成");
+                }
+            }
+        }
+
+        private static void WriteTitle(ExcelWorksheet newWorksheet, ExcelWorksheet worksheet)
+        {
+            int newColumnNum = newWorksheet.Dimension == null ? 0 : newWorksheet.Dimension.End.Column;
+
+            int columnNum = worksheet.Dimension.End.Column;
+            for (int i = 1; i <= columnNum; i++)
+            {
+                string name = worksheet.Cells[3, i].Text.Trim();
+                string type = worksheet.Cells[2, i].Text.Trim();
+                if (name.Length == 0)
+                {
+                    continue;
+                }
+                bool needWriteColumn = true;
+                for (int j = 1; j <= newColumnNum; j++)
+                {
+                    string newName = newWorksheet.Cells[3, j].Text.Trim();
+                    string newType = newWorksheet.Cells[2, i].Text.Trim();
+                    if (name == newName && type == newType)
+                    {
+                        needWriteColumn = false;
+                    }
+                }
+                if (needWriteColumn)
+                {
+                    newColumnNum = newWorksheet.Dimension == null ? 0 : newWorksheet.Dimension.End.Column;
+                    newWorksheet.InsertColumn(newColumnNum + 1, 1);
+
+                    for (int k = 1; k <= 4; k++)
+                    {
+                        newWorksheet.Cells[k, newColumnNum + 1].Value = worksheet.Cells[k, i].Value;
+                    }
+                }
+            }
+            WriteCell(newWorksheet, worksheet);
+        }
+        private static void WriteCell(ExcelWorksheet newWorksheet, ExcelWorksheet worksheet)
+        {
+            int newRowNum = newWorksheet.Dimension == null ? 0 : newWorksheet.Dimension.End.Row;
+            newWorksheet.InsertRow(newRowNum + 1, 2);
+            int newColumnNum = newWorksheet.Dimension == null ? 0 : newWorksheet.Dimension.End.Column;
+
+            int rowNum = worksheet.Dimension.End.Row;
+            int columnNum = worksheet.Dimension.End.Column;
+            for (int i = 5; i <= rowNum; i++)
+            {
+                newRowNum = newWorksheet.Dimension == null ? 0 : newWorksheet.Dimension.End.Row;
+                newWorksheet.InsertRow(newRowNum + 1, 1);
+                int column = 0;
+                for (int j = 1; j <= columnNum; j++)
+                {
+                    string title = worksheet.Cells[3, j].Text.Trim();
+                    if (string.IsNullOrEmpty(title)) continue;
+                    for (int k = column + 1; k <= newColumnNum; k++)
+                    {
+                        string newTitle = newWorksheet.Cells[3, k].Text.Trim();
+                        if (newTitle == title)
+                        {
+                            column = k;
+                            break;
+                        }
+                    }
+
+                    newWorksheet.Cells[newRowNum + 1, column].Value = worksheet.Cells[i, j].Value;
+                }
+            }
+            newRowNum = newWorksheet.Dimension == null ? 0 : newWorksheet.Dimension.End.Row;
+            newWorksheet.InsertRow(newRowNum + 1, 2);
+        }
+        private static void DeleteExcle()
+        {
+            string path = ExcelConfig.excelsCacheFolderPath;
+            if (Directory.Exists(path) == false)
+            {
+                ET.Log.Debug("Path is not Existed!");
+                return;
+            }
+            DirectoryInfo dir = new DirectoryInfo(path);
+            // FileInfo[] files = dir.GetFiles();
+            string[] files = Directory.GetFiles(path);
+            try
+            {
+                foreach (var item in files)
+                {
+                    File.Delete(item);
+                }
+                return;
+            }
+            catch (Exception)
+            {
+                ET.Log.Debug("Delete Failed!");
+                return;
+
+            }
+
+        }
+
     }
 }

+ 15 - 13
GameClient/Assets/Editor/ToolsMenu.cs

@@ -23,6 +23,7 @@ namespace GFGEditor
             BuildBundlesRes,
             UpdateProject,
             ImportExcel,
+            AddExcel,
             ImportArtRes,
         }
 
@@ -128,19 +129,20 @@ namespace GFGEditor
             //try
             //{
 
-                SQLiteHelper.Instance.ClearAllTables();
-                CodeTemplateFactory.Init();
+            SQLiteHelper.Instance.ClearAllTables();
+            CodeTemplateFactory.Init();
 
-                if (!Directory.Exists(ExcelConfig.configCodePath))
-                {
-                    Directory.CreateDirectory(ExcelConfig.configCodePath);
-                }
-                if (!Directory.Exists(ExcelConfig.configArrayCodePath))
-                {
-                    Directory.CreateDirectory(ExcelConfig.configArrayCodePath);
-                }
+            if (!Directory.Exists(ExcelConfig.configCodePath))
+            {
+                Directory.CreateDirectory(ExcelConfig.configCodePath);
+            }
+            if (!Directory.Exists(ExcelConfig.configArrayCodePath))
+            {
+                Directory.CreateDirectory(ExcelConfig.configArrayCodePath);
+            }
 
-                ExcelReader.ReadExcel(CodeBuilder.GenerateCode);
+            ExcelReader.WriteExcle();
+            ExcelReader.ReadExcel(CodeBuilder.GenerateCode);
             //}
             //catch (Exception e)
             //{
@@ -148,7 +150,7 @@ namespace GFGEditor
             //}
             //finally
             //{
-                SQLiteHelper.Instance.CloseConnection();
+            SQLiteHelper.Instance.CloseConnection();
             //}
             //开始扫描表格,自动生成部分数据
             ExcelScanner.StartScan();
@@ -254,7 +256,7 @@ namespace GFGEditor
                 CommitWhenRelease = false;
                 UpdateAndImportArtRes();
             }
-            catch(Exception e)
+            catch (Exception e)
             {
                 Log.Error(e.ToString());
                 ImportArtResTool.ResRootDirNameDressUp = "正式资源";