guodong 3 жил өмнө
parent
commit
f349c23efd

+ 113 - 18
GameClient/Assets/Editor/Excel/CodeBuilder.cs

@@ -7,6 +7,7 @@ using System.Text;
 using UnityEngine;
 using GFGGame;
 using System.Text.RegularExpressions;
+using static Google.Protobuf.Reflection.GeneratedCodeInfo.Types;
 
 namespace GFGEditor
 {
@@ -35,8 +36,12 @@ namespace GFGEditor
             _idDic.Clear();
             _indexs.Clear();
             _hasSameIds = false;
-            string keyName = null;
-            string keyType = null;
+            List<string> keyNames = new List<string>();
+            List<string> keyTypes = new List<string>();
+            List<string> groupNames = new List<string>();
+            List<string> groupTypes = new List<string>();
+            bool needAll = false;
+            bool groupOnly = false;
             int len = rowCollection[1].ItemArray.Length;
             if (len <= 0)
             {
@@ -46,19 +51,100 @@ namespace GFGEditor
             {
                 string annotation = rowCollection[0][i].ToString();
                 string type = rowCollection[1][i].ToString();
-                string name = rowCollection[2][i].ToString();
-                if (i == 0)
+                string nameWhole = rowCollection[2][i].ToString();
+                string[] nameInfos = nameWhole.Split('#');
+                string name = nameInfos[0];
+                if (i == 0 || nameWhole.Contains("#k"))
                 {
-                    keyName = name;
-                    keyType = type;
+                    keyNames.Add(name);
+                    keyTypes.Add(type);
+                }
+                if (nameWhole.Contains("#g"))
+                {
+                    groupNames.Add(name);
+                    groupTypes.Add(type);
+                }
+                if(nameWhole.Contains("#a"))
+                {
+                    needAll = true;
                 }
                 ParseDataColumn(annotation, type, name, i);
             }
-
+            if(keyNames.Count == groupNames.Count)
+            {
+                bool isSame = true;
+                for(var i = 0; i < keyNames.Count; i++)
+                {
+                    if(keyNames[i] != groupNames[i])
+                    {
+                        isSame = false;
+                    }
+                }
+                groupOnly = isSame;
+            }
             //创建sqlite表
             SQLiteHelper.Instance.CreateTable(configArrayName, _names.ToArray(), _types.ToArray());
             AddDataToSql(rowCollection, configName, configArrayName);
 
+            string template = CodeTemplateFactory.ConfigArrayTemplate;
+            string configArrayStr = template;
+            string paramsStr;
+            string colNames;
+            string colValues;
+            //处理查询单条数据函数
+            if (!groupOnly)
+            {
+                string FunctionSingleStr = CodeTemplateFactory.FunctionSingleTemplate;
+                CreateParamsString(keyNames, keyTypes, out paramsStr, out colNames, out colValues);
+                FunctionSingleStr = FunctionSingleStr.Replace("{params}", paramsStr);
+                FunctionSingleStr = FunctionSingleStr.Replace("{colNames}", colNames);
+                FunctionSingleStr = FunctionSingleStr.Replace("{colValues}", colValues);
+                configArrayStr = configArrayStr.Replace("{singleFunction}", FunctionSingleStr);
+                if(groupNames.Count > 0)
+                {
+
+                    _declarationBuilder.AppendFormat("\t\t//{0}", "组合key");
+                    _declarationBuilder.AppendLine();
+                    _declarationBuilder.AppendFormat("\t\tpublic {0} {1};", "string", "combinedKey");
+                    _declarationBuilder.AppendLine();
+                    _assignmentBuilder.AppendFormat("\t\t\t{0} = \"{1}\";", "combinedKey", string.Join("_", keyNames));
+                    _assignmentBuilder.AppendLine();
+                }
+            }
+            else
+            {
+                configArrayStr = configArrayStr.Replace("{singleFunction}", "");
+            }
+
+            //处理查询多条数据函数
+            if (groupNames.Count > 0)
+            {
+                string FunctionGroupStr = groupOnly? CodeTemplateFactory.FunctionGroupOnlyTemplate : CodeTemplateFactory.FunctionGroupTemplate;
+                CreateParamsString(groupNames, groupTypes, out paramsStr, out colNames, out colValues);
+                FunctionGroupStr = FunctionGroupStr.Replace("{params}", paramsStr);
+                FunctionGroupStr = FunctionGroupStr.Replace("{colNames}", colNames);
+                FunctionGroupStr = FunctionGroupStr.Replace("{colValues}", colValues);
+
+                configArrayStr = configArrayStr.Replace("{groupFunction}", FunctionGroupStr);
+            }
+            else
+            {
+                configArrayStr = configArrayStr.Replace("{groupFunction}", "");
+            }
+            //处理全部数据函数
+            if(needAll)
+            {
+                configArrayStr = configArrayStr.Replace("{editorConditionStart}", "");
+                configArrayStr = configArrayStr.Replace("{editorConditionEnd}", "");
+            }
+            else
+            {
+                configArrayStr = configArrayStr.Replace("{editorConditionStart}", "#if UNITY_EDITOR");
+                configArrayStr = configArrayStr.Replace("{editorConditionEnd}", "#endif");
+            }
+            //名称处理
+            configArrayStr = configArrayStr.Replace("{CfgName}", configName);
+            configArrayStr = configArrayStr.Replace("{CfgArrayName}", configArrayName);
             //生成游戏反序列化代码
             string configStr = CodeTemplateFactory.ConfigTemplate.Replace("{CfgName}", configName);
             configStr = configStr.Replace("{variable declaration}", _declarationBuilder.ToString());
@@ -68,17 +154,7 @@ namespace GFGEditor
             {
                 sw.Write(configStr);
             }
-
-            _declarationBuilder.Clear();
-            string template = CodeTemplateFactory.ConfigArrayTemplate;
-            if (_hasSameIds)
-            {
-                template = CodeTemplateFactory.ConfigArrayTemplate2;
-            }
-            string configArrayStr = template.Replace("{CfgName}", configName);
-            configArrayStr = configArrayStr.Replace("{CfgArrayName}", configArrayName);
-            configArrayStr = configArrayStr.Replace("{keyName}", keyName);
-            configArrayStr = configArrayStr.Replace("{keyType}", keyType);
+            //生成管理类代码
             using (StreamWriter sw = new StreamWriter(ExcelConfig.configArrayCodePath + configArrayName + ".cs"))
             {
                 sw.Write(configArrayStr);
@@ -245,5 +321,24 @@ namespace GFGEditor
             }
         }
 
+        private static void CreateParamsString(List<string> keyNames, List<string> keyTypes, out string paramStr, out string colNames, out string colValues)
+        {
+            paramStr = "";
+            colNames = "";
+            colValues = "";
+            for (var i = 0; i < keyNames.Count; i++)
+            {
+                paramStr += keyTypes[i] + " " + keyNames[i];
+                colNames += $"nameof({keyNames[i]})";
+                colValues += $"{keyNames[i]}.ToString()";
+                if (i < keyNames.Count - 1)
+                {
+                    paramStr += ", ";
+                    colNames += ", ";
+                    colValues += ", ";
+                }
+            }
+        }
+        
     }
 }

+ 13 - 11
GameClient/Assets/Editor/Excel/CodeTemplateFactory.cs

@@ -9,7 +9,9 @@ namespace GFGEditor
 
         public static string ConfigTemplate { get; private set; }
         public static string ConfigArrayTemplate { get; private set; }
-        public static string ConfigArrayTemplate2 { get; private set; }
+        public static string FunctionGroupTemplate { get; private set; }
+        public static string FunctionGroupOnlyTemplate { get; private set; }
+        public static string FunctionSingleTemplate { get; private set; }
         //public static string ConfigTemplateEditor { get => _configTemplateEditor; }
         //public static string ConfigArrayTemplateEditor { get => _configArrayTemplateEditor; }
 
@@ -23,19 +25,19 @@ namespace GFGEditor
             {
                 ConfigArrayTemplate = sr.ReadToEnd();
             }
-            using (StreamReader sr = new StreamReader(ExcelConfig.templatePath + "ConfigArray2.txt"))
+            using (StreamReader sr = new StreamReader(ExcelConfig.templatePath + "FunctionGroup.txt"))
             {
-                ConfigArrayTemplate2 = sr.ReadToEnd();
+                FunctionGroupTemplate = sr.ReadToEnd();
             }
 
-            //using (StreamReader sr = new StreamReader(ExcelConfig.templatePath + "ConfigEditor.txt"))
-            //{
-            //    _configTemplateEditor = sr.ReadToEnd();
-            //}
-            //using (StreamReader sr = new StreamReader(ExcelConfig.templatePath + "ConfigArrayEditor.txt"))
-            //{
-            //    _configArrayTemplateEditor = sr.ReadToEnd();
-            //}
+            using (StreamReader sr = new StreamReader(ExcelConfig.templatePath + "FunctionGroupOnly.txt"))
+            {
+                FunctionGroupOnlyTemplate = sr.ReadToEnd();
+            }
+            using (StreamReader sr = new StreamReader(ExcelConfig.templatePath + "FunctionSingle.txt"))
+            {
+                FunctionSingleTemplate = sr.ReadToEnd();
+            }
         }
 
     }

+ 1 - 1
GameClient/Assets/Editor/Excel/Scanner/ItemApproachScanner.cs

@@ -74,7 +74,7 @@ namespace GFGEditor
                 {
                     if ((!cfg.name.Contains("原始") && !cfg.name.Contains("默认")) || cfg.id >= 1000000)
                     {
-                        Debug.LogErrorFormat("物品 {0} {1} 没有获取途径", cfg.id, cfg.name);
+                        //Debug.LogErrorFormat("物品 {0} {1} 没有获取途径", cfg.id, cfg.name);
                     }
                 }
             }

+ 5 - 7
GameClient/Assets/Editor/Excel/Template/ConfigArray.txt

@@ -5,15 +5,12 @@ namespace GFGGame
     public partial class {CfgArrayName} : SingletonBase<{CfgArrayName}>
     {
     
-        private Dictionary<{keyType}, {CfgName}> _cfgDic = new Dictionary<{keyType}, {CfgName}>();
-        private {CfgName}[] _allDatas;
+{singleFunction}
 
+{groupFunction}
 
-        public {CfgName} GetCfg({keyType} {keyName})
-        { 
-            return ConfigUtil.GetCfg<{keyType}, {CfgName}>("{CfgArrayName}", "{keyName}", {keyName}, _cfgDic);
-        }
-        
+{editorConditionStart}
+        private {CfgName}[] _allDatas;
         public {CfgName}[] dataArray
         {
             get
@@ -25,5 +22,6 @@ namespace GFGGame
                 return _allDatas;
             }
         }
+{editorConditionEnd}
     }
 }

+ 0 - 29
GameClient/Assets/Editor/Excel/Template/ConfigArray2.txt

@@ -1,29 +0,0 @@
-using System.Collections.Generic;
-
-namespace GFGGame
-{
-    public partial class {CfgArrayName} : SingletonBase<{CfgArrayName}>
-    {
-        private Dictionary<{keyType}, {CfgName}[]> _cfgsDic = new Dictionary<{keyType}, {CfgName}[]>();
-
-        public {CfgName}[] GetCfgs({keyType} {keyName})
-        {
-            return ConfigUtil.GetCfgs<{keyType}, {CfgName}>("{CfgArrayName}", "{keyName}", {keyName}, _cfgsDic);
-        }
-
-#if UNITY_EDITOR
-        private {CfgName}[] _allDatas;
-        public {CfgName}[] dataArray
-        {
-            get
-            {
-                if (_allDatas == null)
-                {
-                    _allDatas = ConfigUtil.GetAllCfgs<{CfgName}>("{CfgArrayName}");
-                }
-                return _allDatas;
-            }
-        }
-#endif
-    }
-}

+ 12 - 0
GameClient/Assets/Editor/Excel/Template/FunctionGroup.txt

@@ -0,0 +1,12 @@
+        private Dictionary<string, {CfgName}[]> _cfgsGroupDic = new Dictionary<string, {CfgName}[]>();
+        public {CfgName}[] GetCfgs({params})
+        {
+            var colNames = new string[] { {colNames}};
+            var colValues = new string[] { {colValues} };
+            return ConfigUtil.GetCfgs<{CfgName}>("{CfgArrayName}", colNames, colValues, _cfgsGroupDic, HandleCfgInGroup);
+        }
+        
+        private void HandleCfgInGroup(CardLvlCfg cfg)
+        {
+            _cfgsDic[cfg.combinedKey] = cfg;
+        }

+ 1 - 1
GameClient/Assets/Editor/Excel/Template/ConfigArray2.txt.meta → GameClient/Assets/Editor/Excel/Template/FunctionGroup.txt.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: 4c713690b67a39a4eafcf4658fd4a69d
+guid: 23eea2587dbf5c249b141a177bf129a5
 TextScriptImporter:
   externalObjects: {}
   userData: 

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

@@ -0,0 +1,7 @@
+        private Dictionary<string, {CfgName}[]> _cfgsGroupDic = new Dictionary<string, {CfgName}[]>();
+        public {CfgName}[] GetCfgs({params})
+        {
+            var colNames = new string[] { {colNames}};
+            var colValues = new string[] { {colValues} };
+            return ConfigUtil.GetCfgs<{CfgName}>("{CfgArrayName}", colNames, colValues, _cfgsGroupDic);
+        }

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

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

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

@@ -0,0 +1,7 @@
+        private Dictionary<string, {CfgName}> _cfgsDic = new Dictionary<string, {CfgName}>();
+        public {CfgName} GetCfg({params})
+        { 
+            var colNames = new string[] { {colNames}};
+            var colValues = new string[] { {colValues} };
+            return ConfigUtil.GetCfg<{CfgName}>("{CfgArrayName}", colNames, colValues, _cfgsDic);
+        }

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

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

+ 1 - 1
GameClient/Assets/Game/CSShare

@@ -1 +1 @@
-Subproject commit 3526f01fb4a402a5b9dfb0b54d30871adf2a6993
+Subproject commit 8e272bd5cd6a2b25bc0f3a4a1371dcee9774589b

+ 2 - 2
GameClient/Assets/Game/HotUpdate/Data/CardDataManager.cs

@@ -278,7 +278,7 @@ namespace GFGGame
             List<CardLvlCfg> listCardLvCfgs = CardCfgManager.GetCardLvCfgsByRarity(rarity);
             showLv = curLv;
             showExp = curExp + hasExp;
-            CardLvlCfg tCurCfg = CardLvlCfgArray.Instance.GetCfg(rarity + "_" + showLv);
+            CardLvlCfg tCurCfg = CardLvlCfgArray.Instance.GetCfg(showLv, rarity);
             while (showExp >= tCurCfg.needExp && showLv <= listCardLvCfgs.Count)
             {
                 showLv++;
@@ -289,7 +289,7 @@ namespace GFGGame
                     showExp = tCurCfg.needExp;
                     break;
                 }
-                tCurCfg = CardLvlCfgArray.Instance.GetCfg(rarity + "_" + showLv);
+                tCurCfg = CardLvlCfgArray.Instance.GetCfg(showLv, rarity);
                 showExp -= tCurCfg.needExp;
             }
         }

+ 4 - 8
GameClient/Assets/Game/HotUpdate/ExcelConfig/Manager/CardCfgManager.cs

@@ -20,8 +20,7 @@ namespace GFGGame
         /// <returns></returns>
         public static CardLvlCfg GetCardLvCfgByRarityAndLv(int rarity, int lv)
         {
-            string id = rarity + "_" + lv;
-            return CardLvlCfgArray.Instance.GetCfg(id);
+            return CardLvlCfgArray.Instance.GetCfg(lv, rarity);
         }
         public static CardStarCfg GetCardStarCfgByTypeAndRarityAndStar(int type, int rarity, int star)
         {
@@ -41,8 +40,7 @@ namespace GFGGame
               
                 int _rarity = 1;
                 int _lv = 1;
-                string _key = "1_1";
-                CardLvlCfg lvCfg = CardLvlCfgArray.Instance.GetCfg(_key);
+                CardLvlCfg lvCfg = CardLvlCfgArray.Instance.GetCfg(_lv, _rarity);
 
                 while (lvCfg != null)
                 {
@@ -53,14 +51,12 @@ namespace GFGGame
                     _cardLvCfgDic[_rarity.ToString()].Add(lvCfg);
 
                     _lv++;
-                    _key = string.Format("{0}_{1}", _rarity, _lv);
-                    lvCfg = CardLvlCfgArray.Instance.GetCfg(_key);
+                    lvCfg = CardLvlCfgArray.Instance.GetCfg(_lv, _rarity);
                     if (lvCfg != null) continue;
 
                     _lv = 1;
                     _rarity++;
-                    _key = string.Format("{0}_{1}", _rarity, _lv);
-                    lvCfg = CardLvlCfgArray.Instance.GetCfg(_key);
+                    lvCfg = CardLvlCfgArray.Instance.GetCfg(_lv, _rarity);
                     if (lvCfg == null) break;
                 }
             }

+ 3 - 3
GameClient/Assets/Game/HotUpdate/Views/Card/CardFosterView.cs

@@ -201,7 +201,7 @@ namespace GFGGame
             {
                 return;
             }
-            _comFosterBottom.m_listLvConsume.numItems = cardLvCfg.materiarsArr.Length;
+            _comFosterBottom.m_listLvConsume.numItems = GlobalCfgArray.globalCfg.materiarsArr.Length;
 
         }
 
@@ -209,7 +209,7 @@ namespace GFGGame
         {
             UI_ComConsume listItem = UI_ComConsume.Proxy(obj);
             CardLvlCfg cardLvCfg = CardCfgManager.GetCardLvCfgByRarityAndLv(_viewData.itemCfg.rarity, _viewData.lv);
-            ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(cardLvCfg.materiarsArr[index]);
+            ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(GlobalCfgArray.globalCfg.materiarsArr[index]);
             listItem.m_loaItem.url = ResPathUtil.GetIconPath(itemCfg);
             listItem.m_txtNum.text = ItemDataManager.GetItemNum(itemCfg.id).ToString();
             listItem.m_txtUseCount.text = "0";
@@ -670,7 +670,7 @@ namespace GFGGame
             if (!CardDataManager.isFullLv(_viewData.id, _viewData.lv, false))
             {
                 CardLvlCfg cardLvCfg = CardCfgManager.GetCardLvCfgByRarityAndLv(_viewData.itemCfg.rarity, _showLv);
-                _comFosterBottom.m_listLvConsume.numItems = cardLvCfg.materiarsArr.Length;
+                _comFosterBottom.m_listLvConsume.numItems = GlobalCfgArray.globalCfg.materiarsArr.Length;
             }
             if (!CardDataManager.isFullStar(_viewData.id, _viewData.star, false))
             {

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