自己也是xlua新手,刚开始不知道如何从lua访问c#方法,然后google后,也是很普通需要在扩展类加上
[XLua.LuaCallCSharp],自己的确也是加了,但是在unity运行的时候还是不行,报nil
经过一番尝试后,发现如果lua需要访问C#扩展方法,需要先清空代码,然后再重新生成,有更好的方式,欢迎留言交流
[XLua.LuaCallCSharp]
public static class EngineExt
{
static public Vector3 ScreenToWorldPoint(this RectTransform trans, Vector2 screenPoint, Camera cam = null)
{
if (cam == null)
{
var cvs = trans.gameObject.GetUICanvas();
if (cvs != null)
{
cam = cvs.worldCamera;
}
}
Vector3 worldPos;
RectTransformUtility.ScreenPointToWorldPointInRectangle(trans, screenPoint, cam, out worldPos);
return worldPos;
}
}
local worldPos = this.heroObjTempl.RectTransform:ScreenToWorldPoint(scrnPos, nil)
跪求打赏
本文地址:https://blog.csdn.net/caiqimin__/article/details/107335015
如对本文有疑问, 点击进行留言回复!!
Mobilenetv3-ssd训练VOC格式数据集loss出现nan:数据本身出现问题
Android PackageManagerService(二)下载安装详解
Asp.Net Core 3.1 Web Api 返回数据字段被转换为小驼峰格式的解决办法
已知两点经纬度,计算偏移角(正北为0,顺时针为正,逆时针为负)
解决问题“Could not load file or assembly xxxxxxx or one of its dependencies”
网友评论