这两天正在学习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,