zhaoyang 3 年 前
コミット
5fc092f29b

+ 10 - 2
GameClient/Assets/Editor/Excel/CodeBuilder.cs

@@ -129,15 +129,16 @@ namespace GFGEditor
 
             }
 
+            string strDiapose = "_allDatas = null;\n";
+
 
-            string ConstructorStr = CodeTemplateFactory.ConstructorTemplate;
-            configArrayStr = configArrayStr.Replace("{Constructor}", ConstructorStr);
 
             string singleFunction = "";
             //处理查询单条数据函数
             if (!groupOnly)
             {
                 singleFunction = HandleSingleFunction("key", keyName, keyType, "GetCfg", "_cfgsDic", configArrayStr);
+                strDiapose = string.Format("{0}\t\t\t{1}\n", strDiapose, "_cfgsDic.Clear();");
             }
             foreach (string key in keyNames.Keys)
             {
@@ -145,6 +146,7 @@ namespace GFGEditor
                 string cfgsDicName = string.Format("_cfgsDicBy{0}", string.Join("And", keyNames[key]));
 
                 singleFunction = singleFunction + HandleSingleFunction("combinedKey_" + key, keyNames[key], keyTypes[key], functionName, cfgsDicName, configArrayStr);
+                strDiapose = string.Format("{0}\t\t\t{1}.Clear();\n", strDiapose, cfgsDicName);
             }
             configArrayStr = configArrayStr.Replace("{singleFunction}", singleFunction);
 
@@ -159,6 +161,7 @@ namespace GFGEditor
                     string functionName = groupNames.Count == 1 ? "GetCfgs" : string.Format("GetCfgsBy{0}", string.Join("And", groupNames[key]));
                     string cfgsGroupDicName = string.Format("_cfgsGroupDic{0}", index0);
                     groupFunction = groupFunction + HandleGroupFunction("groupKey_" + key, groupNames[key], groupTypes[key], functionName, cfgsGroupDicName, configArrayStr);
+                    strDiapose = string.Format("{0}\t\t\t{1}.Clear();", strDiapose, cfgsGroupDicName);
                     index0++;
                 }
             }
@@ -168,10 +171,15 @@ namespace GFGEditor
             //处理全部数据函数
             string FunctionAllStr = CodeTemplateFactory.FunctionAllTemplate;
             configArrayStr = configArrayStr.Replace("{allFunction}", FunctionAllStr);
+            configArrayStr = configArrayStr.Replace("{Constructor}", CodeTemplateFactory.ConstructorTemplate);
+            configArrayStr = configArrayStr.Replace("{Dispose}", CodeTemplateFactory.DisposeTemplate);
+            configArrayStr = configArrayStr.Replace("{StrDiapose}", strDiapose);
 
             configArrayStr = configArrayStr.Replace("{editorConditionStart}", "");
             configArrayStr = configArrayStr.Replace("{editorConditionEnd}", "");
 
+
+
             List<string> singleStrArry = new List<string>();
             if (!groupOnly)
             {

+ 20 - 0
GameClient/Assets/Editor/Excel/CodeTemplateFactory.cs

@@ -10,11 +10,15 @@ namespace GFGEditor
         public static string ConfigTemplate { get; private set; }
         public static string ConfigArrayTemplate { get; private set; }
         public static string ConstructorTemplate { get; private set; }
+        public static string DisposeTemplate { get; private set; }
         public static string FunctionSingleTemplate { get; private set; }
         public static string FunctionGroupTemplate { get; private set; }
         public static string FunctionAllTemplate { get; private set; }
         public static string FunctionAllSingleBlockTemplate { get; private set; }
         public static string FunctionAllGroupBlockTemplate { get; private set; }
+        public static string DisposeAllCfgsCacheTemplate { get; private set; }
+        public static string FunctionDisposeTemplate { get; private set; }
+        public static string StrCfgArrayDisposeTemplate { get; private set; }
         //public static string ConfigTemplateEditor { get => _configTemplateEditor; }
         //public static string ConfigArrayTemplateEditor { get => _configArrayTemplateEditor; }
 
@@ -33,6 +37,10 @@ namespace GFGEditor
             {
                 ConstructorTemplate = sr.ReadToEnd();
             }
+            using (StreamReader sr = new StreamReader(ExcelConfig.templatePath + "Dispose.txt"))
+            {
+                DisposeTemplate = sr.ReadToEnd();
+            }
             using (StreamReader sr = new StreamReader(ExcelConfig.templatePath + "FunctionSingle.txt"))
             {
                 FunctionSingleTemplate = sr.ReadToEnd();
@@ -54,6 +62,18 @@ namespace GFGEditor
             {
                 FunctionAllGroupBlockTemplate = sr.ReadToEnd();
             }
+            using (StreamReader sr = new StreamReader(ExcelConfig.templatePath + "DisposeAllCfgsCache.txt"))
+            {
+                DisposeAllCfgsCacheTemplate = sr.ReadToEnd();
+            }
+            using (StreamReader sr = new StreamReader(ExcelConfig.templatePath + "FunctionDispose.txt"))
+            {
+                FunctionDisposeTemplate = sr.ReadToEnd();
+            }
+            using (StreamReader sr = new StreamReader(ExcelConfig.templatePath + "StrCfgArrayDisposeBlock.txt"))
+            {
+                StrCfgArrayDisposeTemplate = sr.ReadToEnd();
+            }
         }
 
     }

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

@@ -25,6 +25,11 @@ namespace GFGEditor
         /// </summary>
         public const string configArrayCodePath = "Assets/Game/CSShare/GFG//HotUpdate/ExcelConfig/GenCode/Array/";
 
+        /// <summary>
+        /// 存放数据Dispose文件的文件夹路径
+        /// </summary>
+        public const string configDataDisposePath = "Assets/Game/CSShare/GFG//HotUpdate/ExcelConfig/GenCode/";
+
 
         /// <summary>
         /// 存放Excel转化CS文件的文件夹路径

+ 25 - 9
GameClient/Assets/Editor/Excel/ExcelReader.cs

@@ -15,44 +15,59 @@ namespace GFGEditor
         {
             string[] files = Directory.GetFiles(ExcelConfig.excelsFolderPath);
             int totalCount = files.Length;
+            string strCfgArrayDispose = "";
             for (int i = 0; i < totalCount; i++)
             {
                 string filePath = files[i];
                 string fileName = Path.GetFileNameWithoutExtension(filePath);
-                if(!fileName.Contains("~"))
+                if (!fileName.Contains("~"))
                 {
                     ET.Log.Debug($"fileName {fileName}");
                     Stream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
                     ExcelPackage excelPackage = new ExcelPackage(stream);
                     //IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
                     //DataSet result = excelReader.AsDataSet();
-                    
-                    HandleTableCollection(excelPackage.Workbook.Worksheets, rowCollectionHandler);
+
+                    HandleTableCollection(excelPackage.Workbook.Worksheets, rowCollectionHandler, out string dispose);
+                    strCfgArrayDispose = strCfgArrayDispose + dispose;
                 }
             }
+            string functionDispose = CodeTemplateFactory.FunctionDisposeTemplate;
+            functionDispose = functionDispose.Replace("{StrCfgArrayDispose}", strCfgArrayDispose);
+            string disposeAllCfgsCache = CodeTemplateFactory.DisposeAllCfgsCacheTemplate;
+            disposeAllCfgsCache = disposeAllCfgsCache.Replace("{FunctionDispose}", functionDispose);
+            //创建管理类代码
+            using (StreamWriter sw = new StreamWriter(ExcelConfig.configDataDisposePath + "DisposeAllCfgsCache.cs"))
+            {
+                sw.Write(disposeAllCfgsCache);
+            }
         }
 
-        private static void HandleTableCollection(ExcelWorksheets Worksheets, RowCollectionHandler rowCollectionHandler)
+        private static void HandleTableCollection(ExcelWorksheets Worksheets, RowCollectionHandler rowCollectionHandler, out string strCfgArrayDispose)
         {
+            strCfgArrayDispose = "";
             for (int i = 1; i <= Worksheets.Count; i++)
             {
                 ExcelWorksheet worksheet = Worksheets[i];
-                HandleTable(worksheet, rowCollectionHandler);
+                string configArrayName = HandleTable(worksheet, rowCollectionHandler);
+                if (string.IsNullOrEmpty(configArrayName)) continue;
+                string dispose = CodeTemplateFactory.StrCfgArrayDisposeTemplate.Replace("{configArrayName}", configArrayName);
+                strCfgArrayDispose = strCfgArrayDispose + "\n" + dispose;
             }
         }
 
-        private static void HandleTable(ExcelWorksheet worksheet, RowCollectionHandler rowCollectionHandler)
+        private static string HandleTable(ExcelWorksheet worksheet, RowCollectionHandler rowCollectionHandler)
         {
             string[] names = worksheet.Name.Split('_');
             if (names.Length < 2)
             {
                 //未正确命名的表格
-                return;
+                return "";
             }
             if (worksheet.Name.Contains("#"))
             {
                 //被注释的表格
-                return;
+                return "";
             }
             string configItemName = names[1];
             string managerTag = "";
@@ -62,9 +77,10 @@ namespace GFGEditor
             }
             //文件名及管理器名
             string configManagerName = string.Format(ExcelConfig.CONFIG_ARRAY_TEMPLATE, configItemName, managerTag);
-            
 
             rowCollectionHandler(worksheet, configItemName, configManagerName);
+
+            return configManagerName;
         }
 
     }

+ 2 - 0
GameClient/Assets/Editor/Excel/Template/ConfigArray.txt

@@ -6,6 +6,8 @@ namespace GFGGame
     {
 {Constructor}
 
+{Dispose}
+
 {singleFunction}
 
 {groupFunction}

+ 1 - 1
GameClient/Assets/Editor/Excel/Template/Constructor.txt

@@ -1,4 +1,4 @@
 		public {CfgArrayName} ()
 		{ 
 			{CfgName}[] dataArray =this.dataArray;
-		}
+		}

+ 4 - 0
GameClient/Assets/Editor/Excel/Template/Dispose.txt

@@ -0,0 +1,4 @@
+		public void Diapose()
+		{
+			{StrDiapose}
+		}

+ 7 - 0
GameClient/Assets/Editor/Excel/Template/Dispose.txt.meta

@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: 43d41ac30cf568740b75844160546443
+TextScriptImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 7 - 0
GameClient/Assets/Editor/Excel/Template/DisposeAllCfgsCache.txt

@@ -0,0 +1,7 @@
+namespace GFGGame
+{
+    public partial class DisposeAllCfgsCache : SingletonBase<DisposeAllCfgsCache>
+    {
+{FunctionDispose}
+    }
+}

+ 7 - 0
GameClient/Assets/Editor/Excel/Template/DisposeAllCfgsCache.txt.meta

@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: 140aba55e8700624e9689126e9a7505a
+TextScriptImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 4 - 0
GameClient/Assets/Editor/Excel/Template/FunctionDispose.txt

@@ -0,0 +1,4 @@
+        public void DisposeAll()
+        {
+			{StrCfgArrayDispose}
+        }

+ 7 - 0
GameClient/Assets/Editor/Excel/Template/FunctionDispose.txt.meta

@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: 837fe2a751846a2429f73cd667dbf304
+TextScriptImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 0
GameClient/Assets/Editor/Excel/Template/StrCfgArrayDisposeBlock.txt

@@ -0,0 +1 @@
+			{configArrayName}.Instance.Diapose();

+ 7 - 0
GameClient/Assets/Editor/Excel/Template/StrCfgArrayDisposeBlock.txt.meta

@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: 8c9570e58f00665409c08ddcef1ebcb6
+TextScriptImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

BIN
GameClient/Assets/ResIn/Config/excelConfig.sqlite.bytes