这个示例工程主要是为了说明在什么情况下Lua调用不了C#的泛型方法
支持的方法
一个或多个泛型参数都可以被Lua调用
public void Test1<T>(T a) where T : Foo1Parent//class
{
Debug.Log(string.Format("Test1<{0}>", typeof(T)));
}
public T1 Test2<T1, T2>(T1 a, T2 b, GameObject c) where T1 : Foo1Parent where T2 : Foo2Parent//class class
{
Debug.Log(string.Format("Test2<{0},{1}>", typeof(T1), typeof(T2)), c);
return a;
}
不支持的方法
// 不支持生成lua的泛型方法(没有泛型约束)
public void UnsupportedMethod1<T>(T a)
{
Debug.Log("UnsupportedMethod1");
}
// 不支持生成lua的泛型方法(缺少带约束的泛型参数)
public void UnsupportedMethod2<T>() where T : Foo1Parent
{
Debug.Log(string.Format("UnsupportedMethod2<{0}>", typeof(T)));
}
// 不支持生成lua的泛型方法(泛型约束必须为class)
public void UnsupportedMethod3<T>(T a) where T : IDisposable
{
Debug.Log(string.Format("UnsupportedMethod3<{0}>", typeof(T)));
}
以上规则对于扩展方法也是适用的,示例工程中也有测试