|
@@ -7,6 +7,7 @@ using System.Text;
|
|
using UnityEngine;
|
|
using UnityEngine;
|
|
using GFGGame;
|
|
using GFGGame;
|
|
using System.Text.RegularExpressions;
|
|
using System.Text.RegularExpressions;
|
|
|
|
+using static Google.Protobuf.Reflection.GeneratedCodeInfo.Types;
|
|
|
|
|
|
namespace GFGEditor
|
|
namespace GFGEditor
|
|
{
|
|
{
|
|
@@ -35,8 +36,12 @@ namespace GFGEditor
|
|
_idDic.Clear();
|
|
_idDic.Clear();
|
|
_indexs.Clear();
|
|
_indexs.Clear();
|
|
_hasSameIds = false;
|
|
_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;
|
|
int len = rowCollection[1].ItemArray.Length;
|
|
if (len <= 0)
|
|
if (len <= 0)
|
|
{
|
|
{
|
|
@@ -46,19 +51,100 @@ namespace GFGEditor
|
|
{
|
|
{
|
|
string annotation = rowCollection[0][i].ToString();
|
|
string annotation = rowCollection[0][i].ToString();
|
|
string type = rowCollection[1][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);
|
|
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表
|
|
//创建sqlite表
|
|
SQLiteHelper.Instance.CreateTable(configArrayName, _names.ToArray(), _types.ToArray());
|
|
SQLiteHelper.Instance.CreateTable(configArrayName, _names.ToArray(), _types.ToArray());
|
|
AddDataToSql(rowCollection, configName, configArrayName);
|
|
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);
|
|
string configStr = CodeTemplateFactory.ConfigTemplate.Replace("{CfgName}", configName);
|
|
configStr = configStr.Replace("{variable declaration}", _declarationBuilder.ToString());
|
|
configStr = configStr.Replace("{variable declaration}", _declarationBuilder.ToString());
|
|
@@ -68,17 +154,7 @@ namespace GFGEditor
|
|
{
|
|
{
|
|
sw.Write(configStr);
|
|
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"))
|
|
using (StreamWriter sw = new StreamWriter(ExcelConfig.configArrayCodePath + configArrayName + ".cs"))
|
|
{
|
|
{
|
|
sw.Write(configArrayStr);
|
|
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 += ", ";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|