unity2022.2.11 生成代码时有非泛型方法带泛型参数的情况,没有排除
如题,例如Resources下 的方法 public unsafe static void InstanceIDsToValidArray(NativeArray<int> instanceIDs, NativeArray<bool> validArray) Transform下的方法 public unsafe void InverseTransformDirections(ReadOnlySpan<Vector3> directions, Span<Vector3> transformedDirections) 不排除这些方法,生成的代码会报编译错误。
生成的代码: if(gen_param_count == 2&& translator.Assignable<System.ReadOnlySpan<int>>(L, 1)&& translator.Assignable<System.Span<bool>>(L, 2)) 报错: error CS0306: The type 'Span<bool>' may not be used as a type argument
unity 2022.2.11
https://github.com/Tencent/xLua/blob/master/Assets/XLua/Doc/faq.md#unity-2018%E5%8F%8A%E4%BB%A5%E4%B8%8A%E7%89%88%E6%9C%AC%E5%85%BC%E5%AE%B9%E6%80%A7%E9%97%AE%E9%A2%98%E8%A7%A3%E5%86%B3
遇到一样的问题了,也是使用的 Unity 2022版本。楼主后来怎么解决的?
遇到一样的问题了,也是使用的 Unity 2022版本。楼主后来怎么解决的?
试了下,用BlackList可以在生成时排除掉所有Span、ReadOnlySpan
[BlackList]
public static Func<MemberInfo, bool> NoSpan = (memberInfo) =>
{
return !(memberInfo.DeclaringType.IsGenericType && memberInfo.DeclaringType.GetGenericTypeDefinition() == typeof(Span<>));
};
如果有新增需要排除的泛型类型,可以添加到 BlackGenerateTypeList 内。 可以按照以下写法,根据对应的报错成员信息,实现对应的排除方式。
public static List<Type> BlackGenericTypeList = new List<Type>()
{
typeof(Span<>),
typeof(ReadOnlySpan<>),
};
private static bool IsBlacklistedGenericType(Type type)
{
if (!type.IsGenericType) return false;
return BlackGenericTypeList.Contains(type.GetGenericTypeDefinition());
}
[BlackList] public static Func<MemberInfo, bool> GenericTypeFilter = (memberInfo) =>
{
switch (memberInfo)
{
case PropertyInfo propertyInfo:
return IsBlacklistedGenericType(propertyInfo.PropertyType);
case ConstructorInfo constructorInfo:
return constructorInfo.GetParameters().Any(p => IsBlacklistedGenericType(p.ParameterType));
case MethodInfo methodInfo:
return methodInfo.GetParameters().Any(p => IsBlacklistedGenericType(p.ParameterType));
default:
return false;
}
};
可以暂时用我改过的版本, 直接屏蔽掉 Span 和 ReadOnlySpan 相关的生成. 就等仓库管理员合并代码了