1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| // 用对象名字作为加载脚本的查询名字 string luaname = GameRoot.Instance.GlobleUtil.NameDeleteClone(gameObject.name);
// 直接用byte[] dostring AssetBundle bundle = AssetBundle.LoadFromFile("Assets/StreamingAssets/main/lua"); TextAsset lua = bundle.LoadAsset("MainUI.lua", typeof(TextAsset)) as TextAsset; luaEnv.DoString(lua.bytes, luaname, scriptEnv);
// 用 custom loader加载 但是无法使用self,也无法获取luaAwake这类的方法 //luaEnv.DoString("require '" + luaname + "'", luaname, scriptEnv);
Action luaAwake = scriptEnv.GetInPath<Action>("MainUI.awake"); luaStart = scriptEnv.GetInPath<Action>("MainUI.start"); luaUpdate = scriptEnv.GetInPath<Action>("MainUI.update"); luaOnDestroy = scriptEnv.GetInPath<Action>("MainUI.ondestroy");
|