From dc39f170a8570f7b96cf20697d1ba3c98e7d6900 Mon Sep 17 00:00:00 2001 From: SlimeNull <69663231+SlimeNull@users.noreply.github.com> Date: Mon, 18 Dec 2023 11:17:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=9C=A8=20Unity=2020?= =?UTF-8?q?22=20=E4=B8=8B=E7=94=9F=E6=88=90=E4=BB=A3=E7=A0=81=E6=8A=A5=20S?= =?UTF-8?q?pan=20=E6=97=A0=E6=B3=95=E4=BD=9C=E6=B3=9B=E5=9E=8B=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E7=9A=84=E9=97=AE=E9=A2=98=20(#1104)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/XLua/Editor/XLuaUnityDefaultConfig.cs | 53 ++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Assets/XLua/Editor/XLuaUnityDefaultConfig.cs diff --git a/Assets/XLua/Editor/XLuaUnityDefaultConfig.cs b/Assets/XLua/Editor/XLuaUnityDefaultConfig.cs new file mode 100644 index 000000000..a72fa48a0 --- /dev/null +++ b/Assets/XLua/Editor/XLuaUnityDefaultConfig.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using XLua; + +/// +/// xLua 默认配置 +/// +static class XLuaUnityDefaultConfig +{ + +#if UNITY_2022_1_OR_NEWER + static bool IsSpanType(Type type) + { + if (!type.IsGenericType) + return false; + + var genericDefinition = type.GetGenericTypeDefinition(); + + return + genericDefinition == typeof(Span<>) || + genericDefinition == typeof(ReadOnlySpan<>); + } + + static bool IsSpanMember(MemberInfo memberInfo) + { + switch (memberInfo) + { + case FieldInfo fieldInfo: + return IsSpanType(fieldInfo.FieldType); + + case PropertyInfo propertyInfo: + return IsSpanType(propertyInfo.PropertyType); + + case ConstructorInfo constructorInfo: + return constructorInfo.GetParameters().Any(p => IsSpanType(p.ParameterType)); + + case MethodInfo methodInfo: + return methodInfo.GetParameters().Any(p => IsSpanType(p.ParameterType)) || IsSpanType(methodInfo.ReturnType); + + default: + return false; + } + } + + [BlackList] + public static Func SpanMembersFilter = IsSpanMember; + +#endif +} \ No newline at end of file