xlua笔记(二)

xlua中不支持通过子物体获取组件

所以在需要一些没有的功能的时候需要自己对类扩展方法,或者自己写方法  需要添加 [LuaCallCSharp]

泛型方法必须满足:

1.泛型方法必须带约束

2.并且且必须为Class

3.并且泛型方法必须带有泛型参数

扩展方法

支持对自定义类的扩展方法

支持对自定义类的泛型扩展方法, 但是扩展类型必须是约束类型 如:

public static T Extension1<T>(this T a) where T : Foo1Parent
{
Debug.Log(string.Format("Extension1<{0}>", typeof (T)));
return a;
}

public static T Extension2<T>(this T a, GameObject b) where T : Foo1Parent
{
Debug.Log(string.Format("Extension2<{0}>", typeof (T)), b);
return a;
}

public static void Extension2<T1, T2>(this T1 a, T2 b) where T1 : Foo1Parent where T2 : Foo2Parent
{
Debug.Log(string.Format("Extension2<{0},{1}>", typeof (T1), typeof (T2)));
}

不能像下边这样,对GameObject扩展但是约束为Component

public static T UnsupportedExtension<T>(this GameObject obj) where T : Component
{
  return obj.GetComponent<T>();
}

本博客所有内容均为原创,转载请注明出处.
原文地址:https://www.cnblogs.com/what-lee/p/10107419.html