找回密码
 立即注册
查看: 473|回复: 0

Unity接入XLua问题汇总

[复制链接]
发表于 2021-9-29 14:20 | 显示全部楼层 |阅读模式
Unity接入XLua问题汇总



        一、This type must add to CSharpCallLua
      二、Type cannot be null in method 'GetComponent'


一、This type must add to CSharpCallLua

如Unity中更新XLua时遇到
  1. LuaException: c# exception:This type must add to CSharpCallLua: UnityEngine.Events.UnityAction<float>
  2. LuaException: c# exception:System.InvalidCastException: This type must add to CSharpCallLua: System.Action<bool>
复制代码
在XLua ExampleConfig.cs中添加如下配置,然后重新 Generate Code 即可
  1. //C#静态调用Lua的配置(包括事件的原型),仅可以配delegate,interface
  2.     [CSharpCallLua]
  3.     public static List<Type> CSharpCallLua = new List<Type>() {
  4.             typeof(Action),
  5.             typeof(Func<double, double, double>),
  6.             typeof(Action<string>),
  7.             typeof(Action<double>),
  8.             typeof(Action<bool>),
  9.             typeof(Action<float>),
  10.             typeof(UnityEngine.Events.UnityAction),
  11.         };
复制代码
二、Type cannot be null in method ‘GetComponent’
  1. 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
  2.       at XLua.OverloadMethodWrap.Call (System.IntPtr L) [0x00000] in <00000000000000000000000000000000>:0
  3.       at XLua.MethodWrap.Call (System.IntPtr L) [0x00000] in <00000000000000000000000000000000>:0
  4.       at XLua.StaticLuaCallbacks.FixCSFunction (System.IntPtr L) [0x00000] in <00000000000000000000000000000000>:0
  5.     stack traceback:
  6.             [C]: in method 'GetComponent'
复制代码
出错行代码
  1. closeButton:GetComponent("Button").onClick:AddListener(self:OnClose(true))
复制代码
将通过 “Button” 字符串获取组件改为 通过 typeof(Button) 获取组件。修改为如下:
  1. closeButton:GetComponent(typeof(Button)).onClick:AddListener(self:OnClose(true))
复制代码
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-11-24 18:58 , Processed in 0.088479 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表