From 24d7dbc6777c3973b5517ea44dd9967159c53e35 Mon Sep 17 00:00:00 2001
From: ALEXTANG <574809918@qq.com>
Date: Tue, 28 May 2024 18:09:13 +0800
Subject: [PATCH] =?UTF-8?q?EventInterfaceGenerate=E6=94=AF=E6=8C=81List?=
=?UTF-8?q?=E4=B8=8EDictionary(=E4=BD=86=E4=B8=8D=E6=8E=A8=E8=8D=90?=
=?UTF-8?q?=E7=94=A8)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
EventInterfaceGenerate支持List与Dictionary(但不推荐用)
---
.../EventInterface/EventInterfaceGenerate.cs | 69 ++++++++++++++++++-
1 file changed, 67 insertions(+), 2 deletions(-)
diff --git a/UnityProject/Assets/TEngine/Editor/EventInterface/EventInterfaceGenerate.cs b/UnityProject/Assets/TEngine/Editor/EventInterface/EventInterfaceGenerate.cs
index 0506832a..b44f492b 100644
--- a/UnityProject/Assets/TEngine/Editor/EventInterface/EventInterfaceGenerate.cs
+++ b/UnityProject/Assets/TEngine/Editor/EventInterface/EventInterfaceGenerate.cs
@@ -187,14 +187,20 @@ public static class EventInterfaceGenerate
var parameterInfo = parameterInfos[i];
Type type = parameterInfo.ParameterType;
string paramName = parameterInfo.Name;
+
+ if (type.FullName.StartsWith("System.Collections.Generic.List"))
+ {
+ Debug.Log("123");
+ }
+
if (i == parameterInfos.Length - 1)
{
- paramStr += $"{type.FullName} {paramName}";
+ paramStr += $"{GetTypeName(parameterInfo)} {paramName}";
paramStr2 += $"{paramName}";
}
else
{
- paramStr += $"{type.FullName} {paramName},";
+ paramStr += $"{GetTypeName(parameterInfo)} {paramName},";
paramStr2 += $"{paramName},";
}
}
@@ -214,6 +220,65 @@ public static class EventInterfaceGenerate
}
}
}
+
+ private static string GetTypeName(ParameterInfo parameterInfo)
+ {
+ if (parameterInfo.ParameterType.IsList() && parameterInfo.ParameterType.IsGenericType)
+ {
+ string typeName = parameterInfo.ParameterType.FullName.Split('`')[0];
+
+ return $"{typeName}<{parameterInfo.ParameterType.GenericTypeArguments[0].FullName}>";
+ }
+ else if (parameterInfo.ParameterType.IsDictionary() && parameterInfo.ParameterType.IsGenericType)
+ {
+ string typeName = parameterInfo.ParameterType.FullName.Split('`')[0];
+
+ return $"{typeName}<{parameterInfo.ParameterType.GenericTypeArguments[0].FullName},{parameterInfo.ParameterType.GenericTypeArguments[1].FullName}>";
+ }
+ else
+ {
+ return parameterInfo.ParameterType.FullName;
+ }
+
+ return parameterInfo.ParameterType.FullName;
+ }
+
+ ///
+ /// 判断类型是否为可操作的列表类型
+ ///
+ ///
+ ///
+ public static bool IsList(this Type type)
+ {
+ if (typeof (System.Collections.IList).IsAssignableFrom(type))
+ {
+ return true;
+ }
+
+ foreach (var it in type.GetInterfaces())
+ {
+ if (it.IsGenericType && typeof (IList<>) == it.GetGenericTypeDefinition())
+ return true;
+ }
+
+ return false;
+ }
+
+ public static bool IsDictionary(this Type type)
+ {
+ if (typeof (System.Collections.IDictionary).IsAssignableFrom(type))
+ {
+ return true;
+ }
+
+ foreach (var it in type.GetInterfaces())
+ {
+ if (it.IsGenericType && typeof (IDictionary) == it.GetGenericTypeDefinition())
+ return true;
+ }
+
+ return false;
+ }
}
public static class EventInterfaceGenerateTag