shunelly 2020-05-09
CSharp侧的代码:
using UnityEngine;
namespace LGSTEST
{
public class Lgs : MonoBehaviour
{
void Update()
{
if (Input.GetMouseButtonDown(0))
{
TestParams(12, "110");
}
}
void TestParams(params object[] param)
{
Debug.Log(param[0]);
}
}
}用Xlua对方法 TestParams 进行修复的时候,lua代码的写法:
xlua.hotfix(CS.LGSTEST.Lgs, "TestParams", function(self, ...)
local param = {...};
print("------- " .. param[1] .." ++++++ " .. param[2])
print(param[3])
end)运行结果:

需要注意的有两一点:
lua侧对C#的可变参数的接受及使用方式,... 接受,{...}包成数组再使用,索引是从1开始的。