public bool LoadLuaZip(string luaZipFileName) { if (string.IsNullOrEmpty(luaZipFileName)) { Log.LogE("LoadLuaZip Error Arg!"); return(false); } string filePath = FileUtil.CombinePath(JW.Res.FileUtil.GetIFSExtractPath(), luaZipFileName + ".bytes"); if (!JW.Res.FileUtil.IsFileExist(filePath)) { JW.Common.Log.LogE("LoadLuaZip Failed Not Exist File"); return(false); } if (_curLuaZip != null) { _curLuaZip.Close(); _curLuaZip = null; } _curLuaZip = new IFSFile(); if (_curLuaZip.InitWithFile(filePath) == false) { JW.Common.Log.LogE("LuaZip Init Failed"); return(false); } else { Log.LogD("<color=yellow>{0} LuaZip Init Successed!</color>", luaZipFileName); return(true); } }
//----------------------lua文件包读取方式---------------- public IEnumerator LoadMainLua(LuaEnv lua, System.Action <int> callback = null) { if (callback != null) { callback(LoadStateLoading); } // string filePath = FileUtil.CombinePath(JW.Res.FileUtil.GetIFSExtractPath(), "Main_Lua.bytes"); if (!JW.Res.FileUtil.IsFileExist(filePath)) { JW.Common.Log.LogE("Get Main_Lua.bytes pack File Failed"); if (callback != null) { callback(LoadStateFail); } } else { _curLuaZip = new IFSFile(); if (_curLuaZip.InitWithFile(filePath) == false) { JW.Common.Log.LogE("Get Main_Lua Init Failed"); if (callback != null) { callback(LoadStateFail); } } else { Log.LogD("<color=yellow>Init Main_Lua Done!</color>"); // lua.AddLoader(CustomLuaLoader); //启动 lua.DoString("require('Boot')"); //收集脚本 LuaFunction collectLua = lua.Global.GetInPath <LuaFunction>("CollectScripts"); if (collectLua != null) { string[] scripts = collectLua.Func <bool, string[]>(true); if (scripts == null || scripts.Length == 0) { JW.Common.Log.LogE("Collect lua scripts failed."); } else { for (int i = 0; i < scripts.Length; i++) { lua.DoString(string.Format("require('{0}')", scripts[i])); if ((i + 1) % 10 == 0) { yield return(null); } } } } collectLua = null; if (callback != null) { callback(LoadStateSuccess); } yield return(null); Log.LogD("Load main_lua All Done!"); _curLuaZip.Close(); _curLuaZip = null; } } }