diff --git a/Assets/Unity-Tools/Core/ExcelResolver/Editor/ExcelResolverEditorWindow.ReadExcel.cs b/Assets/Unity-Tools/Core/ExcelResolver/Editor/ExcelResolverEditorWindow.ReadExcel.cs index 3712081..705cf94 100644 --- a/Assets/Unity-Tools/Core/ExcelResolver/Editor/ExcelResolverEditorWindow.ReadExcel.cs +++ b/Assets/Unity-Tools/Core/ExcelResolver/Editor/ExcelResolverEditorWindow.ReadExcel.cs @@ -11,11 +11,11 @@ namespace Tools.ExcelResolver.Editor { private enum TableType { - SingleKeyTable, // 单主键表 - UnionMultiKeyTable, // 多主键表(联合索引) - MultiKeyTable, // 多主键表(独立索引) - NotKetTable, // 无主键表 - ColumnTable, // 纵表 + SingleKeyTable, // 单主键表 + UnionMultiKeyTable, // 多主键表(联合索引) + MultiKeyTable, // 多主键表(独立索引) + NotKetTable, // 无主键表 + ColumnTable, // 纵表 } @@ -38,10 +38,7 @@ namespace Tools.ExcelResolver.Editor } var type = CheckTableType(worksheet); - foreach (var i in keyIndex) - { - Debug.Log($"{type} {i}"); - } + GetFieldData(worksheet); } } @@ -50,7 +47,7 @@ namespace Tools.ExcelResolver.Editor var startColumn = worksheet.Dimension.Start.Column; // 起始列 var endColumn = worksheet.Dimension.End.Column; // 结束列 - string config = worksheet.Cells[1, 1].Value.ToString(); + string config = worksheet.Cells[1, 1].Text; var type = TableType.SingleKeyTable; if (config.Contains("SingleKeyTable")) { @@ -98,6 +95,10 @@ namespace Tools.ExcelResolver.Editor { type = TableType.ColumnTable; } + else + { + Debug.LogError("配置错误"); + } return type; @@ -117,5 +118,20 @@ namespace Tools.ExcelResolver.Editor return keyIndex; } } + + private void GetFieldData(ExcelWorksheet worksheet) + { + var startColumn = worksheet.Dimension.Start.Column; // 起始列 + var endColumn = worksheet.Dimension.End.Column; // 结束列 + Debug.Log(endColumn); + for (int col = 2; col <= endColumn; col++) + { + FieldData fieldData = new FieldData(); + fieldData.name = worksheet.Cells[2, col].Text; + fieldData.description = worksheet.Cells[4, col].Text; + fieldData.type = TypeUtil.GetType(worksheet.Cells[3, col].Text); + Debug.Log(fieldData.type); + } + } } } \ No newline at end of file diff --git a/Assets/Unity-Tools/Core/ExcelResolver/Editor/ExcelResolverEditorWindow.WriteDataCode.cs b/Assets/Unity-Tools/Core/ExcelResolver/Editor/ExcelResolverEditorWindow.WriteDataCode.cs index 20a17b0..cf012bd 100644 --- a/Assets/Unity-Tools/Core/ExcelResolver/Editor/ExcelResolverEditorWindow.WriteDataCode.cs +++ b/Assets/Unity-Tools/Core/ExcelResolver/Editor/ExcelResolverEditorWindow.WriteDataCode.cs @@ -1,7 +1,16 @@ -using Tools.Editor.CodeGenKit; +using System; +using Tools.Editor.CodeGenKit; namespace Tools.ExcelResolver.Editor { + internal class FieldData + { + public string name; + public Type type; + public string description; + + } + public sealed partial class ExcelResolverEditorWindow { private int[] keyIndex; diff --git a/Assets/Unity-Tools/Core/Util/TypeUtil.cs b/Assets/Unity-Tools/Core/Util/TypeUtil.cs new file mode 100644 index 0000000..4b0f2ef --- /dev/null +++ b/Assets/Unity-Tools/Core/Util/TypeUtil.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; + +namespace Tools +{ + public static class TypeUtil + { + public static Type GetTypeByString(string typeText) + { + return typeText switch + { + "int" => typeof(int), + "float" => typeof(float), + "string" => typeof(string), + "bool" => typeof(bool), + + "List" => typeof(List), + "List" => typeof(List), + "List" => typeof(List), + "List" => typeof(List), + + "List>" => typeof(List>), + "List>" => typeof(List>), + "List>" => typeof(List>), + "List>" => typeof(List>), + + "enum" => typeof(Enum), + "DateTime" => typeof(DateTime), + _ => GetType(typeText) + }; + } + + /// + /// 参考:https://learn.microsoft.com/zh-cn/dotnet/api/system.type.gettype?view=net-8.0 + /// + /// + /// + /// + public static Type GetType(string typeText) + { + // 首先尝试使用Type.GetType + Type type = Type.GetType($"System.{typeText}", false, true); + if (type != null) return type; + + // 如果失败,尝试在UnityEngine命名空间下查找 + // 参数一:"[命名空间.类型名], [程序集名]" + // 参数二:是否抛出异常 + // 参数三:是否区分大小写 + type = Type.GetType($"UnityEngine.{typeText}, UnityEngine", false, true); + if (type != null) return type; + + throw new ArgumentException($"Unsupported type: {typeText}"); + } + } +} \ No newline at end of file diff --git a/Assets/Unity-Tools/Core/Util/TypeUtil.cs.meta b/Assets/Unity-Tools/Core/Util/TypeUtil.cs.meta new file mode 100644 index 0000000..847a70a --- /dev/null +++ b/Assets/Unity-Tools/Core/Util/TypeUtil.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 5e00e18dfb2244dbb54a891cd3505c9c +timeCreated: 1736011944 \ No newline at end of file