首页 > 其他 > 详细

xlua笔记(二)

时间:2018-12-12 11:39:56      阅读:203      评论:0      收藏:0      [点我收藏+]

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>();
}

 

xlua笔记(二)

原文:https://www.cnblogs.com/what-lee/p/10107419.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!