|
Unity接入XLua问题汇总
一、This type must add to CSharpCallLua
二、Type cannot be null in method 'GetComponent'
一、This type must add to CSharpCallLua
如Unity中更新XLua时遇到- LuaException: c# exception:This type must add to CSharpCallLua: UnityEngine.Events.UnityAction<float>
- LuaException: c# exception:System.InvalidCastException: This type must add to CSharpCallLua: System.Action<bool>
复制代码 在XLua ExampleConfig.cs中添加如下配置,然后重新 Generate Code 即可- //C#静态调用Lua的配置(包括事件的原型),仅可以配delegate,interface
- [CSharpCallLua]
- public static List<Type> CSharpCallLua = new List<Type>() {
- typeof(Action),
- typeof(Func<double, double, double>),
- typeof(Action<string>),
- typeof(Action<double>),
- typeof(Action<bool>),
- typeof(Action<float>),
- typeof(UnityEngine.Events.UnityAction),
- };
复制代码 二、Type cannot be null in method ‘GetComponent’
- LuaException: c# exception:Type cannot be null.,stack: at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <00000000000000000000000000000000>:0
- at XLua.OverloadMethodWrap.Call (System.IntPtr L) [0x00000] in <00000000000000000000000000000000>:0
- at XLua.MethodWrap.Call (System.IntPtr L) [0x00000] in <00000000000000000000000000000000>:0
- at XLua.StaticLuaCallbacks.FixCSFunction (System.IntPtr L) [0x00000] in <00000000000000000000000000000000>:0
- stack traceback:
- [C]: in method 'GetComponent'
复制代码 出错行代码- closeButton:GetComponent("Button").onClick:AddListener(self:OnClose(true))
复制代码 将通过 “Button” 字符串获取组件改为 通过 typeof(Button) 获取组件。修改为如下:- closeButton:GetComponent(typeof(Button)).onClick:AddListener(self:OnClose(true))
复制代码 |
|