关于Unity在Xlua调用Lua脚本函数时报错This type must add to CSharpCallLua 解决办法

使用委托来获取xlua中的function是不行的

报错脚本示范

 // [CSharpCallLua]
  //  public delegate void LuaBtnEvent(int index);
    
    //[CSharpCallLua]
   // public static LuaBtnEvent BtnEvent;//被LuaModer引用

// ButtonEvent.BtnEvent=luaEnv.Global.Get<ButtonEvent.LuaBtnEvent>("PlotEventBar");

即使全部接口打好标签并且在编辑器中把兼容等级改为4.X 打包出去还是会出问题

建议在lua脚本中建立一个空的table

再把方法塞进去
比如

main={}

function PlotEventBar(ID)
    if ID<11 then
        if ID==2 then
            ChangeValue("HP",10)
        end
        if ID==3 then
            if EffectFind("一个测试状态+") then
                Effect("超强的测试状态")
            else
            Effect("一个测试状态",true)
            end
        end
        if ID==4 then
            Move("Up",1)
        end
    end
    
end
main.PlotEventBar=PlotEventBar

然后在c#端

            if (PlotEvent.Plots[index].Specail)
            {
                LuaModer.luaEnv.DoString($"main.PlotEventBar({index})");
            }

就可以正常运作这个方法了

猜你喜欢

转载自blog.csdn.net/qq_58804985/article/details/128166819