XLua 重写C#的一些注意

这两天正在学习XLua,正好线上版本有个BUG需要热更代码。将几个方法用Lua进行了重写,这里记录了几个作为一个lua新手遇到的几个问题。

首先是重写如下C#方法,该方法在BaseDance类里面,命名空间为Dance。

private Vector3 GetRankPos(int index, int count) {
    if(index == 0) {
        return Vector3.zero;
    }
    if(count == 3 || count == 2) {
        if(index == 1) {
            return new Vector3(1.7f, 0, -1f);
        }
        if(index == 2) {
            return new Vector3(-1.7f, 0, -1f);
        }
    }
    return new Vector3(-0.8f, 0, -2f);
}

对应的Lua为

xlua.hotfix(CS.Dance.BaseDance, 'GetRankPos', function(self, index, count)
	if index == 0 then
		return CS.UnityEngine.Vector3.zero;
	end
	
	if count == 3 or count == 2 then
		if index == 1 then
			return CS.UnityEngine.Vector3(1.7, 0, -1);
		end
		if index == 2 then
			return CS.UnityEngine.Vector3(-1.7, 0, -1);
		end
	end
	return CS.UnityEngine.Vector3(-0.8, 0, -2);
end)

先来看看官方给的Xlua的几个API,

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值