diff --git a/Assets/ScriptableObject/Generator/Excel.meta b/Assets/ScriptableObject/Excel.meta
similarity index 77%
rename from Assets/ScriptableObject/Generator/Excel.meta
rename to Assets/ScriptableObject/Excel.meta
index f11a703..4a0a229 100644
--- a/Assets/ScriptableObject/Generator/Excel.meta
+++ b/Assets/ScriptableObject/Excel.meta
@@ -1,5 +1,5 @@
fileFormatVersion: 2
-guid: e67c6d5e54b9de94ab4e5d1865feb935
+guid: 5e0421ee85549f24b833a7ea9e0161d7
folderAsset: yes
DefaultImporter:
externalObjects: {}
diff --git a/Assets/ScriptableObject/Generator/Excel/Hero_1.asset b/Assets/ScriptableObject/Excel/Hero_1.asset
similarity index 100%
rename from Assets/ScriptableObject/Generator/Excel/Hero_1.asset
rename to Assets/ScriptableObject/Excel/Hero_1.asset
diff --git a/Assets/ScriptableObject/Generator/Excel/Hero_1.asset.meta b/Assets/ScriptableObject/Excel/Hero_1.asset.meta
similarity index 79%
rename from Assets/ScriptableObject/Generator/Excel/Hero_1.asset.meta
rename to Assets/ScriptableObject/Excel/Hero_1.asset.meta
index 61bce23..6e07775 100644
--- a/Assets/ScriptableObject/Generator/Excel/Hero_1.asset.meta
+++ b/Assets/ScriptableObject/Excel/Hero_1.asset.meta
@@ -1,5 +1,5 @@
fileFormatVersion: 2
-guid: 5d9d9d9b6a4a85b468a248932c5ffc68
+guid: 1dbc2c949eb53844c818697026072761
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
diff --git a/Assets/ScriptableObject/Generator/Excel/Hero_2.asset b/Assets/ScriptableObject/Excel/Hero_2.asset
similarity index 100%
rename from Assets/ScriptableObject/Generator/Excel/Hero_2.asset
rename to Assets/ScriptableObject/Excel/Hero_2.asset
diff --git a/Assets/ScriptableObject/Generator/Excel/Hero_2.asset.meta b/Assets/ScriptableObject/Excel/Hero_2.asset.meta
similarity index 79%
rename from Assets/ScriptableObject/Generator/Excel/Hero_2.asset.meta
rename to Assets/ScriptableObject/Excel/Hero_2.asset.meta
index 878b668..5d30b44 100644
--- a/Assets/ScriptableObject/Generator/Excel/Hero_2.asset.meta
+++ b/Assets/ScriptableObject/Excel/Hero_2.asset.meta
@@ -1,5 +1,5 @@
fileFormatVersion: 2
-guid: 20719aba661cd244f9d4e3b1f45a3e14
+guid: 623b6ecbcd0b3db48a888fc162488552
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
diff --git a/Assets/ScriptableObject/Generator.meta b/Assets/ScriptableObject/Generator.meta
deleted file mode 100644
index c965f3e..0000000
--- a/Assets/ScriptableObject/Generator.meta
+++ /dev/null
@@ -1,8 +0,0 @@
-fileFormatVersion: 2
-guid: 0640585ce4cc1ab43ad546d3258130dc
-folderAsset: yes
-DefaultImporter:
- externalObjects: {}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Unity-Tools/Core/ExcelResolver/Editor/Core/Util/ExcelResolverUtil.TType.cs b/Assets/Unity-Tools/Core/ExcelResolver/Editor/Core/Util/ExcelResolverUtil.TType.cs
new file mode 100644
index 0000000..ce1d314
--- /dev/null
+++ b/Assets/Unity-Tools/Core/ExcelResolver/Editor/Core/Util/ExcelResolverUtil.TType.cs
@@ -0,0 +1,46 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using UnityEngine;
+
+namespace Tools.ExcelResolver.Editor
+{
+ internal static partial class ExcelResolverUtil
+ {
+ ///
+ /// 更具类型字符串获取 TType
+ ///
+ ///
+ ///
+ internal static TType GetTTypeByString(string typeText)
+ {
+ return typeText switch
+ {
+ "int" => new TInt(),
+ "float" => new TFloat(),
+ "string" => new TString(),
+ "bool" => new TBool(),
+ // "Vector2" => typeof(Vector2),
+ // "Vector3" => typeof(Vector3),
+ //
+ // "List" => typeof(List),
+ // "List" => typeof(List),
+ // "List" => typeof(List),
+ // "List" => typeof(List),
+ // "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),
+ _ => null,
+ };
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assets/Unity-Tools/Core/ExcelResolver/Editor/Core/Util/ExcelResolverUtil.TType.cs.meta b/Assets/Unity-Tools/Core/ExcelResolver/Editor/Core/Util/ExcelResolverUtil.TType.cs.meta
new file mode 100644
index 0000000..6a392b1
--- /dev/null
+++ b/Assets/Unity-Tools/Core/ExcelResolver/Editor/Core/Util/ExcelResolverUtil.TType.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 0a88f86b983a4118983088d69a474898
+timeCreated: 1737274824
\ No newline at end of file
diff --git a/Assets/Unity-Tools/Core/ExcelResolver/Editor/Core/Util/ExcelResolverUtil.Type.cs b/Assets/Unity-Tools/Core/ExcelResolver/Editor/Core/Util/ExcelResolverUtil.Type.cs
index 291fc6c..4d49650 100644
--- a/Assets/Unity-Tools/Core/ExcelResolver/Editor/Core/Util/ExcelResolverUtil.Type.cs
+++ b/Assets/Unity-Tools/Core/ExcelResolver/Editor/Core/Util/ExcelResolverUtil.Type.cs
@@ -1,140 +1,102 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using UnityEngine;
namespace Tools.ExcelResolver.Editor
{
internal static partial class ExcelResolverUtil
{
-
- internal static TType GetTTypeByString(string typeText)
- {
- return typeText switch
- {
- "int" => new TInt(),
- "float" => new TFloat(),
- "string" => new TString(),
- "bool" => new TBool(),
- // "Vector2" => typeof(Vector2),
- // "Vector3" => typeof(Vector3),
- //
- // "List" => typeof(List),
- // "List" => typeof(List),
- // "List" => typeof(List),
- // "List" => typeof(List),
- // "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)
- };
- }
-
- internal static Type GetTypeByString(string typeText)
- {
- return typeText switch
- {
- "int" => typeof(int),
- "float" => typeof(float),
- "string" => typeof(string),
- "bool" => typeof(bool),
- "Vector2" => typeof(Vector2),
- "Vector3" => typeof(Vector3),
-
- "List" => typeof(List),
- "List" => typeof(List),
- "List" => typeof(List),
- "List" => typeof(List),
- "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
- ///
- ///
- ///
- ///
- internal 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}");
- }
-
///
/// 类型缓存,避免重复反射查找
+ /// StringComparer.OrdinalIgnoreCase: 忽略键的大小写
///
- internal static readonly Dictionary TypeCache = new(StringComparer.OrdinalIgnoreCase);
+ static readonly Dictionary TypeCache = new(StringComparer.OrdinalIgnoreCase);
///
/// 通过类名(含命名空间)获取 Type,并缓存
///
internal static Type GetOrCacheTypeByName(string typeName)
{
- if (TypeCache.TryGetValue(typeName, out Type cachedType))
+ typeName = typeName.Trim();
+
+ // 如果缓存中存在,直接返回
+ if (TypeCache.TryGetValue(typeName, out var result))
{
- return cachedType;
+ return result;
}
- string namespacedType = $"Tools.ExcelResolver.{typeName}";
- Type type = Type.GetType(namespacedType, false, true) ?? GetTypeFromAllAssemblies(namespacedType);
-
- if (type != null)
+ // 尝试从 Tools.ExcelResolver 命名空间下查找
+ string fullTypeName = $"Tools.ExcelResolver.{typeName}";
+ result = Type.GetType(fullTypeName, false, true) ?? GetTypeFromNecessaryAssemblies(fullTypeName);
+ if (result != null)
{
- TypeCache[typeName] = type;
+ return result;
}
-
- return type;
+
+ throw new ArgumentException($"Unsupported type: {typeName}");
}
- internal static Type GetTypeFromAllAssemblies(string typeName)
+ ///
+ /// 从所有程序集中查找类型
+ ///
+ ///
+ ///
+ ///
+ static Type GetTypeFromNecessaryAssemblies(string fullTypeName)
{
- foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
+ var assemblies = AppDomain.CurrentDomain.GetAssemblies()
+ .Where(a => a.GetName().Name
+ is "UnityEngine"
+ or "Assembly-CSharp"
+ or "Assembly-CSharp-firstpass"
+ or "Assembly-CSharp-Editor"
+ or "Assembly-CSharp-Editor-firstpass");
+
+ foreach (var assembly in assemblies)
{
- var type = assembly.GetType(typeName);
+ var type = assembly.GetType(fullTypeName);
+ if (assembly.GetName().Name is "Assembly-CSharp-Editor" or "Assembly-CSharp-Editor-firstpass")
+ {
+ throw new ArgumentException($"不支持Editor目录下的'{fullTypeName}'类型");
+ }
if (type != null)
{
- TypeCache[typeName] = type;
+ TypeCache[fullTypeName] = type;
return type;
}
}
-
- throw new ArgumentException($"Unsupported type: {typeName}");
+
+ return null;
}
internal static void Dispose()
{
TypeCache.Clear();
}
+
+ /*
+ ///
+ /// 参考:https://learn.microsoft.com/zh-cn/dotnet/api/system.type.gettype?view=net-8.0
+ ///
+ ///
+ ///
+ ///
+ 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/ExcelResolver/Editor/ExcelResolverEditorWindow.WriteSOData.cs b/Assets/Unity-Tools/Core/ExcelResolver/Editor/ExcelResolverEditorWindow.WriteSOData.cs
index e2c4252..80d44fe 100644
--- a/Assets/Unity-Tools/Core/ExcelResolver/Editor/ExcelResolverEditorWindow.WriteSOData.cs
+++ b/Assets/Unity-Tools/Core/ExcelResolver/Editor/ExcelResolverEditorWindow.WriteSOData.cs
@@ -19,10 +19,10 @@ namespace Tools.ExcelResolver.Editor
ReadExcel();
}
- foreach (var data in classCodeDataDict)
+ foreach (var pair in classCodeDataDict)
{
- var worksheet = data.Key;
- var classCodeData = data.Value;
+ var worksheet = pair.Key;
+ var classCodeData = pair.Value;
Type soType = ExcelResolverUtil.GetOrCacheTypeByName(classCodeData.className);