public static void CopyLuaFilesToAssetsPackage() { bool encodeLua = true; //对lua 编译 //准备目标路径 string destination = Path.Combine(Application.dataPath, AssetBundleConfig.AssetsFolderName); destination = Path.Combine(destination, XLuaManager.luaAssetbundleAssetName); //准备源目录 string source = ""; if (Application.platform == RuntimePlatform.WindowsEditor) { source = Path.Combine(Application.dataPath, XLuaManager.luaScriptsFolder); } else if (Application.platform == RuntimePlatform.OSXEditor) { if (encodeLua) { source = Path.Combine(Application.dataPath, "LuaScriptsEncode"); } else { source = Path.Combine(Application.dataPath, XLuaManager.luaScriptsFolder); } } if (source.Length == 0) { Debug.LogError("Source error:" + source); return; } //先删除后copy 否则会失败 GameUtility.SafeDeleteDir(destination, false); GameUtility.CopyFolder(source, destination); //FileUtil.CopyFileOrDirectoryFollowSymlinks(source, destination); //清理非Lua文件 var notLuaFiles = GameUtility.GetSpecifyFilesInFolder(destination, new string[] { ".lua" }, true); if (notLuaFiles != null && notLuaFiles.Length > 0) { for (int i = 0; i < notLuaFiles.Length; i++) { GameUtility.SafeDeleteFile(notLuaFiles[i]); } } //获取所有的lua文件准备编译 var luaFiles = GameUtility.GetSpecifyFilesInFolder(destination, new string[] { ".lua" }, false); if (luaFiles != null && luaFiles.Length > 0) { for (int i = 0; i < luaFiles.Length; i++) { if (encodeLua) { if (Application.platform == RuntimePlatform.WindowsEditor) { // window 平台直接编译 EncodeLuaFile(luaFiles[i], luaFiles[i] + ".bytes"); GameUtility.SafeDeleteFile(luaFiles[i]); } else if (Application.platform == RuntimePlatform.OSXEditor) { // mac 平台,lua_encode.py编译好的文件复制过来,直接重命名 GameUtility.SafeRenameFile(luaFiles[i], luaFiles[i] + ".bytes"); } } else { GameUtility.SafeRenameFile(luaFiles[i], luaFiles[i] + ".bytes"); } } } //移動config文件 string configDes = Path.Combine(Application.dataPath, AssetBundleConfig.AssetsFolderName); configDes = Path.Combine(configDes, "LuaData"); if (!Directory.Exists(configDes)) { Directory.CreateDirectory(configDes); } configDes = Path.Combine(configDes, "Config"); if (!Directory.Exists(configDes)) { Directory.CreateDirectory(configDes); } configDes = Path.Combine(configDes, "Data"); if (!Directory.Exists(configDes)) { Directory.CreateDirectory(configDes); } string configSou = Path.Combine(destination, "Config/Data"); //先删除后copy 否则会失败 GameUtility.SafeDeleteDir(configDes); FileUtil.MoveFileOrDirectory(configSou, configDes); AssetDatabase.Refresh(); Debug.Log("Copy lua files over"); }