require "uiDefine"
报错信息:module 'uiDefine' not found:
no fieldpackage.preload['uiDefine']
no such builtin lib'uiDefine'
解决方法: 在require "ui.uiDefine" 在基于lua根目录的下require全路径,例如Assets/Scripts/lua为根目录
static public class UnityCommonExtension
{
static public void DestroyAllChildren(this GameObject target)
{
foreach (Transform child in target.transform)
{
GameObject.Destroy(child.gameObject);
}
}
}
for i = 1, #headIconParent do
headIconParent[i]:DestroyAllChildren()
End
如果
public static class LuaGenConfig
{
//lua中要使用到C#库的配置,比如C#标准库,或者UnityAPI,第三方库等。
[LuaCallCSharp]
public static List<Type> LuaCallCSharp = new List<Type>()
{
//typeof(UnityCommonExtension),
}
}
报错信息: attemptto call a nil value (method 'DestroyAllChildren')
解决方法:
for i = 1, #headIconParent do
CS.UnityCommonExtension.DestroyAllChildren(headIconParent[i])
End
或者 LuaGenConfig添加上,然后用 headIconParent[i]:DestroyAllChildren()
或 headIconParent[i].DestroyAllChildren(headIconParent[i])即可
for i = 1, pairs(headIconParent) do end
报错信息:'for'limit must be a number
解决方法:用 for i= 1, #headIconParent do end
而for k, v pairs(headIconParent) do end 也可以
C# 的数组传到lua里,
local widgets = {}--go:GetComponentsInChildren("UIWidget",true)
local widArr =InterfaceForLua.GetWidgetArray(go)
for i = 0, widArr.Length - 1 do
table.insert(widgets, widArr[i])
end
但是c#的list传到lua里就不能被识别。
如果定义的是方法,要写function()#### end, 否则不写会执行调用的函数,而不是传进去的方法。
定义的 lua方法,:定义:调用,.定义.调用 , :也用在c#静态方法的调用,省去self
function UIItemIconInfo:CreateItemIcon(itemNum, parent, uniqueName)
local go =ResUtil.LoadGameObject("UI/CommonIcon/ItemIconInfoLua")
local script = {}
setmetatable(script,{__index = UIItemIconInfo}
script.gameObject = go
script.Data = itemNum
script.eName =uniqueName
script:InitEvent()
script:awake()
script:onBindComplete()
script:start()
if parent ~= nil then
parent:AddChildEx(go.transform)
end
go.name =string.format("Item%s", tostring(itemNum.ItemId))
if parent ~= nil andparent:GetComponent("UIWidget") ~= nil then
local parentDepth =parent:GetComponent("UIWidget").depth
local widgets = {} localwidArr = InterfaceForLua.GetWidgetArray(go)
for i = 0, widArr.Length - 1 do
table.insert(widgets, widArr[i])
end
for k in pairs(widgets) do
widgets[k].depth= widgets[k].depth + parentDepth
end
end
return script
end
function UIItemIconInfo:onBindComplete()
self:SetMask(false)
self:ItemIconCanClick(true)
self:AddDragScrollView(false, nil)
self:SetItemIconScale(Vector3.one)
self:SetBackGroundVisable(true, true)
self:SetSelectHide(true)
end
function UIItemIconInfo:SetMask(bVis)
Mask:SetActive(bVis)
End
self 与单例的使用
这些就是lua单例的使用方法
local widgets = {}
local widArr = InterfaceForLua.GetWidgetArray(go) –这个是c#传过来的UIWidget[]
logError(typeof(widgets).." "..typeof(widArr)) -- table userdata
--widgets = widArr --如果能成功,表相等,是引用,一个改另一个跟着改
table.insert(widgets,widArr) --如果能成功,表insert,是独立的表
报错信息:attemptto get length of a userdata value
解决方法:遍历userdata,进行插入表
for i = 0, widArr.Length - 1 do
table.insert(widgets,widArr[i])
end
---------for循环
for i = 1, #widgets do
widgets[i].depth = widgets[i].depth + parentDepth
end
for k in pairs(widgets) do
print(k)
widgets[k].depth = widgets[k].depth +parentDepth
end
-------这两个一样的作用
local widArr = InterfaceForLua.GetWidgetArray(go) 加入local 变量 widArr.Length获取长度 5.2之前table.getn
LuaException: ui.CommonIcon.UIItemIconInfoLua:157: attempt toperform arithmetic on a nil value (field 'depth')
stack traceback:
ui.CommonIcon.UIItemIconInfoLua:157:in field 'CreateItemIcon'
解决方法:
LuaException: c# exception:Non-static method requires atarget.,stack: atSystem.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlagsinvokeAttr, System.Reflection.Binder binder, System.Object[] parameters,System.Globalization.CultureInfo culture) [0x000fe] in/Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:236
atSystem.Reflection.MethodBase.Invoke (System.Object obj, System.Object[]parameters) [0x00000] in/Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115
atXLua.OverloadMethodWrap.Call (IntPtr L) [0x00151] inE:\AAAA\project\client\AAAA\Assets\XLua\Src\MethodWarpsCache.cs:220
at XLua.MethodWrap.Call(IntPtr L) [0x00036] inE:\AAAA\project\client\AAAA\Assets\XLua\Src\MethodWarpsCache.cs:260
stack traceback:
[C]: in field'SetActive'
解决方法:'SetActive'不是static方法,要用:访问
UIItemIconInfo script = go:GetComponent('UIItemIconInfo')
报错信息:syntax error near 'script'
解决方法:声明为local即可
go.transform.localScale =CS.UnityEngine.Vector3(0.7f, 0.7f, 0.7f) (lua中没有new)
报错信息:malformed number near '0.7f'
解决方法:把f去掉,lua没有integer和float类型之分,数值都是用number类型表示的,
attempt to perform arithmetic on a stringvalue
stack traceback:
解决方案:这个写成的c#的语法了,把+ 变成.. 例如print("AAAAAAAAbbb: " + tostring(Data.Reward.Count))
LuaException: error loading modulecoruntine_test from resource, coruntine_test.lua:29: syntax error near 'local'
stack traceback:
[C]:in ?
[C]:in function 'require'
[string"chunk"]:1: in main chunk
解决方法:29行调用到地方检查,就到了require 的地方,比如检查 = 号赋值
LuaException: [string"LuaBehaviour"]:32: attempt to index a thread value (global 'co')
stack traceback:
[string"LuaBehaviour"]:32: in function <[string"LuaBehaviour"]:22>
XLua.LuaEnv.ThrowExceptionFromError (Int32oldTop) (at Assets/XLua/Src/LuaEnv.cs:411)
XLuaGenDelegateImpl0.Invoke7(UnityEngine.GameObject go)
UIEventListener.OnClick () (atAssets/NGUI/Scripts/Internal/UIEventListener.cs:53)
解决方法:直接调用 lua 的协程报错, 然后用包装 Unity 协程 的方法解决
table.getn()提示 attempt to call a nil value (field'getn')
解决方法:Usethe length operator #
asin #foo
.
table.getn
wasdeprecated in 5.1 and removed in 5.2.
functiontable.getn(x) local ret for i in pairs(x) do ret=ret+1 end return ret end
InvalidCastException: This interface mustadd to CSharpCallLua: UIItemIconInfo+myInter
XLua.CodeEmit.EmitInterfaceImpl(System.Type to_be_impl) (at Assets/ThirdParty/XLua/Src/CodeEmit.cs:349)
XLua.ObjectTranslator.CreateInterfaceBridge(IntPtr L, System.Type interfaceType, Int32 idx) (atAssets/ThirdParty/XLua/Src/ObjectTranslator.cs:436)
XLua.ObjectCasters+<genCaster>c__AnonStorey0.<>m__2(IntPtr L, Int32 idx, System.Object target) (atAssets/ThirdParty/XLua/Src/ObjectCasters.cs:447)
XLua.ObjectTranslator.GetObject (IntPtr L,Int32 index, System.Type type) (atAssets/ThirdParty/XLua/Src/ObjectTranslator.cs:656)
XLua.ObjectTranslator.Get[myInter] (IntPtrL, Int32 index, myInter& v) (atAssets/ThirdParty/XLua/Src/ObjectTranslator.cs:669)
解决方法:加上[CSharpCallLua]
LuaException:assets/bundles//lua/logicBase/GenerateLuaData.lua:6: attempt to index a nilvalue (global 'GenerateLuaData')
stack traceback:
assets/bundles//lua/logicBase/GenerateLuaData.lua:6:in main chunk
[C]:in function 'require'
assets/bundles//lua/logicBase/EnterLua.lua:4:in main chunk
[C]:in function 'require'
E:/AAAA_XLua/Assets/LuaFramework/Lua/Main.lua:2:in main chunk
[C]:in function 'require'
[string"chunk"]:1: in main chunk
XLua.LuaEnv.ThrowExceptionFromError (Int32oldTop) (at Assets/ThirdParty/XLua/Src/LuaEnv.cs:411)
XLua.LuaEnv.DoString (System.String chunk,System.String chunkName, XLua.LuaTable env) (atAssets/ThirdParty/XLua/Src/LuaEnv.cs:248)
LuaFramework.LuaManager.StartMain () (atAssets/LuaFramework/Scripts/Manager/LuaManager.cs:52)
LuaFramework.LuaManager.InitStart () (atAssets/LuaFramework/Scripts/Manager/LuaManager.cs:21)
LuaFramework.GameManager.OnInitialize ()(at Assets/LuaFramework/Scripts/Manager/GameManager.cs:252)
LuaFramework.GameManager.OnResourceInited() (at Assets/LuaFramework/Scripts/Manager/GameManager.cs:247)
LuaFramework.GameManager+<OnUpdateResource>c__Iterator1.MoveNext() (at Assets/LuaFramework/Scripts/Manager/GameManager.cs:133)
UnityEngine.SetupCoroutine.InvokeMoveNext(IEnumerator enumerator, IntPtr returnValueAddress) (atC:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
LuaFramework.GameManager:CheckExtractResource()(at Assets/LuaFramework/Scripts/Manager/GameManager.cs:58)
LuaFramework.GameManager:Init() (atAssets/LuaFramework/Scripts/Manager/GameManager.cs:30)
LuaFramework.GameManager:Awake() (at Assets/LuaFramework/Scripts/Manager/GameManager.cs:20)
UnityEngine.GameObject:AddComponent()
LuaFramework.Facade:AddManager(String) (atAssets/LuaFramework/Scripts/Framework/Core/Facade.cs:109)
StartUpCommand:Execute(IMessage) (atAssets/LuaFramework/Scripts/Controller/Command/StartUpCommand.cs:26)
LuaFramework.Controller:ExecuteCommand(IMessage)(at Assets/LuaFramework/Scripts/Framework/Core/Controller.cs:76)
LuaFramework.Facade:SendMessageCommand(String,Object) (at Assets/LuaFramework/Scripts/Framework/Core/Facade.cs:84)
LuaFramework.AppFacade:StartUp() (atAssets/LuaFramework/Scripts/Framework/AppFacade.cs:35)
LuaFramework.Main:Start() (atAssets/LuaFramework/Scripts/Main.cs:10)
解决方法:在lua文件里声明
GenerateLuaData = {}
local this = GenerateLuaData
LuaException: c# exception:c# exception:c#exception:Non-static method requires a target.,stack: at System.Reflection.MonoMethod.Invoke(System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[]parameters, System.Globalization.CultureInfo culture) [0x000fe] in/Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:236
atSystem.Reflection.MethodBase.Invoke (System.Object obj, System.Object[]parameters) [0x00000] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115
atXLua.OverloadMethodWrap.Call (IntPtr L) [0x00151] inE:\AAAA_XLua\Assets\ThirdParty\XLua\Src\MethodWarpsCache.cs:220
atXLua.MethodWrap.Call (IntPtr L) [0x00065] in E:\AAAA_XLua\Assets\ThirdParty\XLua\Src\MethodWarpsCache.cs:267
stack traceback:
[C]:in field 'ItemIconCanClick'
assets/bundles//lua/Controller/ItemTipsCtrl.lua:56:in function <assets/bundles//lua/Controller/ItemTipsCtrl.lua:43>
[C]:in method 'LoadPrefabForLua'
assets/bundles//lua/Controller/ItemTipsCtrl.lua:32:in function <assets/bundles//lua/Controller/ItemTipsCtrl.lua:22>
[C]:in method 'CreatePanel'
assets/bundles//lua/Controller/ItemTipsCtrl.lua:18:in field 'Awake'
E:/AAAA_XLua/Assets/LuaFramework/Lua/Logic/EnterLua.lua:33:in field 'OnInitOK'
E:/AAAA_XLua/Assets/LuaFramework/Lua/Main.lua:6:in function 'Main'
[string"chunk"]:1: in main chunk,stack: at XLua.LuaEnv.ThrowExceptionFromError (Int32 oldTop) [0x00041] inE:\AAAA_XLua\Assets\ThirdParty\XLua\Src\LuaEnv.cs:411
atXLua.LuaFunction.Call (System.Object[] args, System.Type[] returnTypes)[0x0008c] in E:\AAAA_XLua\Assets\ThirdParty\XLua\Src\LuaFunction.cs:168
atXLua.LuaFunction.Call (System.Object[] args) [0x00004] inE:\AAAA_XLua\Assets\ThirdParty\XLua\Src\LuaFunction.cs:183
atResUtil.LoadPrefabForLua (System.String path, XLua.LuaFunction func) [0x0003f]in E:\AAAA_XLua\Assets\Scripts\KLib\common\ResUtil.cs:21
at(wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke(object,object[],System.Exception&)
atSystem.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlagsinvokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfoculture) [0x000d0] in/Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222
stack traceback:
[C]:in method 'LoadPrefabForLua'
assets/bundles//lua/Controller/ItemTipsCtrl.lua:32:in function <assets/bundles//lua/Controller/ItemTipsCtrl.lua:22>
[C]:in method 'CreatePanel'
assets/bundles//lua/Controller/ItemTipsCtrl.lua:18:in field 'Awake'
E:/AAAA_XLua/Assets/LuaFramework/Lua/Logic/EnterLua.lua:33:in field 'OnInitOK'
E:/AAAA_XLua/Assets/LuaFramework/Lua/Main.lua:6:in function 'Main'
[string"chunk"]:1: in main chunk,stack: at XLua.LuaEnv.ThrowExceptionFromError (Int32 oldTop) [0x00041] inE:\AAAA_XLua\Assets\ThirdParty\XLua\Src\LuaEnv.cs:411
atXLua.LuaFunction.Call (System.Object[] args, System.Type[] returnTypes)[0x0008c] in E:\AAAA_XLua\Assets\ThirdParty\XLua\Src\LuaFunction.cs:168
atXLua.LuaFunction.Call (System.Object[] args) [0x00004] inE:\AAAA_XLua\Assets\ThirdParty\XLua\Src\LuaFunction.cs:183
atLuaFramework.PanelManager.CreatePanel (System.String name, XLua.LuaFunctionfunc) [0x000cb] inE:\AAAA_XLua\Assets\LuaFramework\Scripts\Manager\PanelManager.cs:68
at(wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke(object,object[],System.Exception&)
atSystem.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlagsinvokeAttr, System.Reflection.Binder binder, System.Object[] parameters,System.Globalization.CultureInfo culture) [0x000d0] in/Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222
stack traceback:
[C]:in method 'CreatePanel'
assets/bundles//lua/Controller/ItemTipsCtrl.lua:18:in field 'Awake'
E:/AAAA_XLua/Assets/LuaFramework/Lua/Logic/EnterLua.lua:33:in field 'OnInitOK'
E:/AAAA_XLua/Assets/LuaFramework/Lua/Main.lua:6:in function 'Main'
[string"chunk"]:1: in main chunk
XLua.LuaEnv.ThrowExceptionFromError (Int32oldTop) (at Assets/ThirdParty/XLua/Src/LuaEnv.cs:411)
XLua.LuaEnv.DoString (System.String chunk,System.String chunkName, XLua.LuaTable env) (atAssets/ThirdParty/XLua/Src/LuaEnv.cs:248)
LuaFramework.LuaManager.StartMain () (atAssets/LuaFramework/Scripts/Manager/LuaManager.cs:52)
LuaFramework.LuaManager.InitStart () (atAssets/LuaFramework/Scripts/Manager/LuaManager.cs:21)
LuaFramework.GameManager.OnInitialize ()(at Assets/LuaFramework/Scripts/Manager/GameManager.cs:252)
LuaFramework.GameManager.OnResourceInited() (at Assets/LuaFramework/Scripts/Manager/GameManager.cs:247)
LuaFramework.GameManager+<OnUpdateResource>c__Iterator1.MoveNext() (at Assets/LuaFramework/Scripts/Manager/GameManager.cs:133)
UnityEngine.SetupCoroutine.InvokeMoveNext(IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
LuaFramework.GameManager:CheckExtractResource()(at Assets/LuaFramework/Scripts/Manager/GameManager.cs:58)
LuaFramework.GameManager:Init() (atAssets/LuaFramework/Scripts/Manager/GameManager.cs:30)
LuaFramework.GameManager:Awake() (atAssets/LuaFramework/Scripts/Manager/GameManager.cs:20)
UnityEngine.GameObject:AddComponent()
LuaFramework.Facade:AddManager(String) (at Assets/LuaFramework/Scripts/Framework/Core/Facade.cs:109)
StartUpCommand:Execute(IMessage) (atAssets/LuaFramework/Scripts/Controller/Command/StartUpCommand.cs:25)
LuaFramework.Controller:ExecuteCommand(IMessage)(at Assets/LuaFramework/Scripts/Framework/Core/Controller.cs:76)
LuaFramework.Facade:SendMessageCommand(String,Object) (at Assets/LuaFramework/Scripts/Framework/Core/Facade.cs:84)
LuaFramework.AppFacade:StartUp() (atAssets/LuaFramework/Scripts/Framework/AppFacade.cs:35)
LuaFramework.Main:Start() (atAssets/LuaFramework/Scripts/Main.cs:10)
LuaException: c#exception:XLua.LuaException:E:/AAAA_XLua/Assets/LuaFramework/Lua/Controller/PromptCtrl.lua:39:attempt to call a nil value (method 'LoadPrefabForLuabb')
stack traceback:
E:/AAAA_XLua/Assets/LuaFramework/Lua/Controller/PromptCtrl.lua:39:in function<E:/AAAA_XLua/Assets/LuaFramework/Lua/Controller/PromptCtrl.lua:23>
[C]:in method 'CreatePanel'
E:/AAAA_XLua/Assets/LuaFramework/Lua/Controller/PromptCtrl.lua:19:in method 'Awake'
E:/AAAA_XLua/Assets/LuaFramework/Lua/Logic/Game.lua:39:in function<E:/AAAA_XLua/Assets/LuaFramework/Lua/Logic/Game.lua:24>
atXLua.LuaEnv.ThrowExceptionFromError (Int32 oldTop) [0x00041] inE:\AAAA_XLua\Assets\ThirdParty\XLua\Src\LuaEnv.cs:411
atXLua.LuaFunction.Call (System.Object[] args, System.Type[] returnTypes)[0x0008c] in E:\AAAA_XLua\Assets\ThirdParty\XLua\Src\LuaFunction.cs:168
atXLua.LuaFunction.Call (System.Object[] args) [0x00004] inE:\AAAA_XLua\Assets\ThirdParty\XLua\Src\LuaFunction.cs:183
atLuaFramework.PanelManager.CreatePanel (System.String name, XLua.LuaFunctionfunc) [0x000b9] inE:\AAAA_XLua\Assets\LuaFramework\Scripts\Manager\PanelManager.cs:67
atXLua.CSObjectWrap.LuaFrameworkPanelManagerWrap._m_CreatePanel (IntPtr L)[0x00082] inE:\AAAA_XLua\Assets\ThirdParty\XLua\Gen\LuaFrameworkPanelManagerWrap.cs:91
stack traceback:
[C]:in method 'CreatePanel'
E:/AAAA_XLua/Assets/LuaFramework/Lua/Controller/PromptCtrl.lua:19:in method 'Awake'
E:/AAAA_XLua/Assets/LuaFramework/Lua/Logic/Game.lua:39:in function<E:/AAAA_XLua/Assets/LuaFramework/Lua/Logic/Game.lua:24>
XLua.LuaEnv.ThrowExceptionFromError (Int32oldTop) (at Assets/ThirdParty/XLua/Src/LuaEnv.cs:411)
XLua.LuaFunction.Call (System.Object[]args, System.Type[] returnTypes) (atAssets/ThirdParty/XLua/Src/LuaFunction.cs:168)
XLua.LuaFunction.Call (System.Object[]args) (at Assets/ThirdParty/XLua/Src/LuaFunction.cs:183)
LuaFramework.LuaManager.CallFunction(System.String funcName, System.Object[] args) (atAssets/LuaFramework/Scripts/Manager/LuaManager.cs:145)
LuaFramework.Util.CallMethod (System.Stringmodule, System.String func, System.Object[] args) (at Assets/LuaFramework/Scripts/Utility/Util.cs:303)
LuaFramework.GameManager.OnInitialize ()(at Assets/LuaFramework/Scripts/Manager/GameManager.cs:239)
LuaFramework.GameManager.OnResourceInited() (at Assets/LuaFramework/Scripts/Manager/GameManager.cs:230)
LuaFramework.GameManager+<OnUpdateResource>c__Iterator1.MoveNext() (at Assets/LuaFramework/Scripts/Manager/GameManager.cs:116)
UnityEngine.SetupCoroutine.InvokeMoveNext(IEnumerator enumerator, IntPtr returnValueAddress) (atC:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
LuaFramework.GameManager:CheckExtractResource()(at Assets/LuaFramework/Scripts/Manager/GameManager.cs:41)
LuaFramework.GameManager:Init() (atAssets/LuaFramework/Scripts/Manager/GameManager.cs:29)
LuaFramework.GameManager:Awake() (atAssets/LuaFramework/Scripts/Manager/GameManager.cs:20)
UnityEngine.GameObject:AddComponent()
Facade:AddManager(String) (atAssets/LuaFramework/Scripts/Framework/Core/Facade.cs:87)
StartUpCommand:Execute(IMessage) (atAssets/LuaFramework/Scripts/Controller/Command/StartUpCommand.cs:25)
Controller:ExecuteCommand(IMessage) (atAssets/LuaFramework/Scripts/Framework/Core/Controller.cs:57)
Facade:SendMessageCommand(String, Object)(at Assets/LuaFramework/Scripts/Framework/Core/Facade.cs:66)
AppFacade:StartUp() (atAssets/LuaFramework/Scripts/Framework/AppFacade.cs:34)
LuaFramework.Main:Start() (atAssets/LuaFramework/Scripts/Main.cs:11)
把工程里的SoundManager 改成Lua调用的脚本报错信息:
LuaException: c# exception:System.InvalidCastException:Cannot cast from source type to destination type.
at<0x00000> <unknown method>
atFacade.GetManager[SoundManager] (System.String typeName) [0x0002e] inE:\AAAA_XLua\Assets\LuaFramework\Scripts\Framework\Core\Facade.cs:101
atLuaFramework.LuaHelper.GetSoundManager () [0x0000b] inE:\AAAA_XLua\Assets\LuaFramework\Scripts\Utility\LuaHelper.cs:52
atXLua.CSObjectWrap.LuaFrameworkLuaHelperWrap._m_GetSoundManager_xlua_st_ (IntPtrL) [0x0000f] in E:\AAAA_XLua\Assets\ThirdParty\XLua\Gen\LuaFrameworkLuaHelperWrap.cs:179
stack traceback:
[C]:in field 'GetSoundManager'
E:/AAAA_XLua/Assets/LuaFramework/Lua/Common/define.lua:40:in main chunk
[C]:in function 'require'
E:/AAAA_XLua/Assets/LuaFramework/Lua/Main.lua:1:in main chunk
[C]:in function 'require'
[string"chunk"]:1: in main chunk
XLua.LuaEnv.ThrowExceptionFromError (Int32oldTop) (at Assets/ThirdParty/XLua/Src/LuaEnv.cs:411)
XLua.LuaEnv.DoString (System.String chunk,System.String chunkName, XLua.LuaTable env) (atAssets/ThirdParty/XLua/Src/LuaEnv.cs:248)
LuaFramework.LuaManager.StartMain () (atAssets/LuaFramework/Scripts/Manager/LuaManager.cs:55)
LuaFramework.LuaManager.InitStart () (atAssets/LuaFramework/Scripts/Manager/LuaManager.cs:25)
LuaFramework.GameManager.OnInitialize ()(at Assets/LuaFramework/Scripts/Manager/GameManager.cs:235)
LuaFramework.GameManager.OnResourceInited() (at Assets/LuaFramework/Scripts/Manager/GameManager.cs:230)
LuaFramework.GameManager+<OnUpdateResource>c__Iterator1.MoveNext() (at Assets/LuaFramework/Scripts/Manager/GameManager.cs:116)
UnityEngine.SetupCoroutine.InvokeMoveNext(IEnumerator enumerator, IntPtr returnValueAddress) (atC:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
LuaFramework.GameManager:CheckExtractResource()(at Assets/LuaFramework/Scripts/Manager/GameManager.cs:41)
LuaFramework.GameManager:Init() (atAssets/LuaFramework/Scripts/Manager/GameManager.cs:29)
LuaFramework.GameManager:Awake() (atAssets/LuaFramework/Scripts/Manager/GameManager.cs:20)
UnityEngine.GameObject:AddComponent()
Facade:AddManager(String) (atAssets/LuaFramework/Scripts/Framework/Core/Facade.cs:87)
StartUpCommand:Execute(IMessage) (atAssets/LuaFramework/Scripts/Controller/Command/StartUpCommand.cs:24)
Controller:ExecuteCommand(IMessage) (atAssets/LuaFramework/Scripts/Framework/Core/Controller.cs:57)
Facade:SendMessageCommand(String, Object)(at Assets/LuaFramework/Scripts/Framework/Core/Facade.cs:66)
AppFacade:StartUp() (atAssets/LuaFramework/Scripts/Framework/AppFacade.cs:34)
LuaFramework.Main:Start() (atAssets/LuaFramework/Scripts/Main.cs:11)
解决方法:看报错的堆栈,看到define.lua:40: in main chunk (产生了二义性)
开启HOTFIX_ENABLE, 并且Generate Code 之后 运行main.unity3d,关闭之后,报错:
NullReferenceException: Object referencenot set to an instance of an object
XLua.LuaBase.Dispose (BooleandisposeManagedResources) (at Assets/ThirdParty/XLua/Src/LuaBase.cs:65)
XLua.LuaBase.Dispose () (atAssets/ThirdParty/XLua/Src/LuaBase.cs:48)
LuaFramework.LuaView.ClearClick () (atAssets/LuaFramework/Scripts/Common/LuaBehaviour.cs:63)
LuaFramework.LuaView.OnDestroy () (atAssets/LuaFramework/Scripts/Common/LuaBehaviour.cs:71)
Internal_CreateGameObject is not allowed tobe called from a MonoBehaviour constructor (or instance field initializer),call it in Awake or Start instead. Called from MonoBehaviour 'SoundManager' ongame object 'GameManager'.
See "Script Serialization" pagein the Unity Manual for further details.
UnityEngine.GameObject:.ctor(String)
SoundPlayer:.ctor(Int32) (atAssets/Scripts/common/SoundManager.cs:84)
SoundManager:.cctor() (atAssets/Scripts/common/SoundManager.cs:21)
UnityEngine.GameObject:AddComponent()
Facade:AddManager(String) (atAssets/LuaFramework/Scripts/Framework/Core/Facade.cs:87)
StartUpCommand:Execute(IMessage) (atAssets/LuaFramework/Scripts/Controller/Command/StartUpCommand.cs:18)
Controller:ExecuteCommand(IMessage) (atAssets/LuaFramework/Scripts/Framework/Core/Controller.cs:57)
Facade:SendMessageCommand(String, Object)(at Assets/LuaFramework/Scripts/Framework/Core/Facade.cs:66)
AppFacade:StartUp() (atAssets/LuaFramework/Scripts/Framework/AppFacade.cs:34)
LuaFramework.Main:Start() (atAssets/LuaFramework/Scripts/Main.cs:11)
UNetWeaver error: Exception:System.MissingMethodException: Method not found:'Mono.Cecil.ModuleDefinition.ImportReference'.
atUnity.UNetWeaver.Weaver.Weave (System.String assName, IEnumerable`1dependencies, IAssemblyResolver assemblyResolver, System.String unityEngineDLLPath,System.String unityUNetDLLPath, System.String outputDir) [0x0004b] inC:\buildslave\unity\build\Extensions\Networking\Weaver\UNetWeaver.cs:1713
atUnity.UNetWeaver.Weaver.WeaveAssemblies (IEnumerable`1 assemblies,IEnumerable`1 dependencies, IAssemblyResolver assemblyResolver, System.StringoutputDir, System.String unityEngineDLLPath, System.String unityUNetDLLPath)[0x0006e] inC:\buildslave\unity\build\Extensions\Networking\Weaver\UNetWeaver.cs:1837
UnityEngine.DebugLogHandler:Internal_Log(LogType,String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType,Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:LogError(Object)
Unity.UNetWeaver.Log:Error(String) (atC:\buildslave\unity\build\Extensions\Networking\Weaver\Program.cs:20)
Unity.UNetWeaver.Weaver:WeaveAssemblies(IEnumerable`1,IEnumerable`1, IAssemblyResolver, String, String, String) (atC:\buildslave\unity\build\Extensions\Networking\Weaver\UNetWeaver.cs:1844)
Unity.UNetWeaver.Program:Process(String,String, String, String[], String[], IAssemblyResolver, Action`1, Action`1) (atC:\buildslave\unity\build\Extensions\Networking\Weaver\Program.cs:34)
UnityEditor.Scripting.Serialization.Weaver:WeaveInto(String,String, String, String, String[], IAssemblyResolver) (atC:\buildslave\unity\build\Editor\Mono\Scripting\Serialization\Weaver.cs:104)
UnityEditor.Scripting.Serialization.Weaver:WeaveUnetFromEditor(String,String, String, String, Boolean) (atC:\buildslave\unity\build\Editor\Mono\Scripting\Serialization\Weaver.cs:74)
(Filename:C:/buildslave/unity/build/Extensions/Networking/Weaver/Program.cs Line: 20)
解决方法:
The way it worked for me was removing the oldinstallation of Unity that I still had on the mac. Also, I removed Unity 5.4.1and installed 5.4.1 again now on a complete Unity free system. That made theerror disappear.
Failure generating network code.
UnityEngine.DebugLogHandler:Internal_Log(LogType,String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType,Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:LogError(Object)
UnityEditor.Scripting.Serialization.Weaver:WeaveInto(String,String, String, String, String[], IAssemblyResolver) (atC:\buildslave\unity\build\Editor\Mono\Scripting\Serialization\Weaver.cs:106)
UnityEditor.Scripting.Serialization.Weaver:WeaveUnetFromEditor(String,String, String, String, Boolean) (atC:\buildslave\unity\build\Editor\Mono\Scripting\Serialization\Weaver.cs:74)
(Filename:C:/buildslave/unity/build/Editor/Mono/Scripting/Serialization/Weaver.cs Line:106)