static private CopyLuaBytesFiles ( string sourceDir, string destDir, bool appendext = true, string searchPattern = "*.lua", SearchOption, option = SearchOption.AllDirectories ) : void | ||
sourceDir | string | |
destDir | string | |
appendext | bool | |
searchPattern | string | |
option | SearchOption, | |
Résultat | void |
static void AddLuaFiles() { string streamDir = Application.dataPath + "/" + AppConst.LuaTempDir; if (!Directory.Exists(streamDir)) { Directory.CreateDirectory(streamDir); } string[] srcDirs = { Application.dataPath + "/" + AppConst.LuaDir, Application.dataPath + "/" + AppConst.LuaSourceDir }; for (int i = 0; i < srcDirs.Length; i++) { ToLuaMenu.CopyLuaBytesFiles(srcDirs[i], streamDir); } string[] dirs = Directory.GetDirectories(streamDir, "*", SearchOption.AllDirectories); for (int i = 0; i < dirs.Length; i++) { string name = dirs[i].Replace(streamDir, string.Empty); name = name.Replace('\\', '_').Replace('/', '_'); name = "lua/lua_" + name.ToLower() + AppConst.ExtName; string path = "Assets" + dirs[i].Replace(Application.dataPath, ""); AddBuildMap(name, "*.bytes", path); } AddBuildMap("lua/lua" + AppConst.ExtName, "*.bytes", "Assets/" + AppConst.LuaTempDir); }
public static void CopyLuaToResources() { ClearLuaFileDir("Assets/resources/@lua"); // 拷贝过去 ToLuaMenu.CopyLuaBytesFiles(LuaConst.luaDir, "Assets/" + LuaConst.resLuaDir); ToLuaMenu.CopyLuaBytesFiles(LuaConst.toluaDir, "Assets/" + LuaConst.resToLuaDir); AssetDatabase.Refresh(); Debug.Log("Copy lua files over"); }
/// <summary> /// 获取游戏中所有Lua文件的assetbundle 信息,用来打包 /// </summary> /// <param name="config"></param> /// <returns></returns> public static void GenLuaBuild(BuilderConfig config) { //获取所有lua文件的bundle信息,所有lua文件需以.bytes为后缀名,否则不能打进assetbundle // 清空临时lua文件夹,正常情况下是不会有该文件夹的 if (Directory.Exists(sTempLuaDir)) { Directory.Delete(sTempLuaDir, true); } Directory.CreateDirectory(sTempLuaDir); //拷贝(编译)lua文件到临时目录 string[] srcDirs = { CustomSettings.lfuLuaDir , CustomSettings.baseLuaDir , Tools.GetLuaSrcPath() , Tools.GetGFLuaPath() }; foreach (var dir in srcDirs) { if (GameConfig.EncodeLua) { string sourceDir = dir; string[] files = Directory.GetFiles(sourceDir, "*.lua", SearchOption.AllDirectories); int len = sourceDir.Length; if (sourceDir[len - 1] == '/' || sourceDir[len - 1] == '\\') { --len; } for (int j = 0; j < files.Length; j++) { string str = files[j].Remove(0, len); string dest = sTempLuaDir + str + ".bytes"; string _dir = Path.GetDirectoryName(dest); Directory.CreateDirectory(_dir); EncodeLuaFile(files[j], dest, config); } } else { ToLuaMenu.CopyLuaBytesFiles(dir, sTempLuaDir); } } _refreshAssetDb(); while (EditorApplication.isUpdating) { } //通过GenLuaBuildByDir配置AssetBundle name foreach (var luaDir in Directory.GetDirectories(sTempLuaDir, "*", SearchOption.AllDirectories)) { GenLuaBuildByDir(luaDir, "*.bytes"); //Debug.LogWarning("lua Add luaDir:" + luaDir); } GenLuaBuildByDir(sTempLuaDir, "*.bytes"); //Debug.LogWarning("lua Add luaDir: lua/lua"); _refreshAssetDb(); }
/// <summary> /// 处理Lua代码包 /// </summary> static void HandleLuaBundle() { string streamDir = Application.dataPath + "/" + AppConst.LuaTempDir; if (!Directory.Exists(streamDir)) { Directory.CreateDirectory(streamDir); } string[] srcDirs = { CustomSettings.luaDir, CustomSettings.FrameworkPath + "/ToLua/Lua" }; for (int i = 0; i < srcDirs.Length; i++) { if (AppConst.LuaByteMode) { string sourceDir = srcDirs[i]; string[] files = Directory.GetFiles(sourceDir, "*.lua", SearchOption.AllDirectories); int len = sourceDir.Length; if (sourceDir[len - 1] == '/' || sourceDir[len - 1] == '\\') { --len; } for (int j = 0; j < files.Length; j++) { string str = files[j].Remove(0, len); string dest = streamDir + str + ".bytes"; string dir = Path.GetDirectoryName(dest); Directory.CreateDirectory(dir); EncodeLuaFile(files[j], dest); } } else { ToLuaMenu.CopyLuaBytesFiles(srcDirs[i], streamDir); } } string[] dirs = Directory.GetDirectories(streamDir, "*", SearchOption.AllDirectories); for (int i = 0; i < dirs.Length; i++) { string name = dirs[i].Replace(streamDir, string.Empty); name = name.Replace('\\', '_').Replace('/', '_'); name = "lua/lua_" + name.ToLower() + AppConst.ExtName; string path = "Assets" + dirs[i].Replace(Application.dataPath, ""); AddBuildMap(name, "*.bytes", path); } AddBuildMap("lua/lua" + AppConst.ExtName, "*.bytes", "Assets/" + AppConst.LuaTempDir); //-------------------------------处理非Lua文件---------------------------------- string luaPath = AppDataPath + "/StreamingAssets/lua/"; for (int i = 0; i < srcDirs.Length; i++) { paths.Clear(); files.Clear(); string luaDataPath = srcDirs[i].ToLower(); Recursive(luaDataPath); foreach (string f in files) { if (f.EndsWith(".meta") || f.EndsWith(".lua")) { continue; } string newfile = f.Replace(luaDataPath, ""); string path = Path.GetDirectoryName(luaPath + newfile); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string destfile = path + "/" + Path.GetFileName(f); File.Copy(f, destfile, true); } } AssetDatabase.Refresh(); }
/// <summary> /// 处理Lua代码包 /// </summary> static void HandleLuaBundle(string pNowResPath) { //首先创建临时目录,准备进行lua文件的处理。 string streamDir = Application.dataPath + "/" + AppConst.LuaTempDir; if (!Directory.Exists(streamDir)) { Directory.CreateDirectory(streamDir); } UnityEngine.Debug.LogWarning("开始打包Lua,创建临时目录:" + streamDir); //首先将lua文件全部拷贝到临时目录中 string[] srcDirs = { CustomSettings.luaDir, CustomSettings.toluaLuaDir }; for (int i = 0; i < srcDirs.Length; i++) { #pragma warning disable 0162 if (AppConst.LuaByteMode) { string sourceDir = srcDirs[i]; string[] files = Directory.GetFiles(sourceDir, "*.lua", SearchOption.AllDirectories); int len = sourceDir.Length; if (sourceDir[len - 1] == '/' || sourceDir[len - 1] == '\\') { --len; } for (int j = 0; j < files.Length; j++) { string str = files[j].Remove(0, len); string dest = streamDir + str + ".bytes"; string dir = Path.GetDirectoryName(dest); Directory.CreateDirectory(dir); EncodeLuaFile(files[j], dest); } } else { ToLuaMenu.CopyLuaBytesFiles(srcDirs[i], streamDir); } #pragma warning restore 0162 } string[] dirs = Directory.GetDirectories(streamDir, "*", SearchOption.AllDirectories); for (int i = 0; i < dirs.Length; i++) { string name = dirs[i].Replace(streamDir, string.Empty); name = name.Replace('\\', '_').Replace('/', '_'); name = "lua/lua_" + name.ToLower() + AppConst.ExtName; string path = "Assets" + dirs[i].Replace(Application.dataPath, ""); AddBuildMap(name, "*.bytes", path); }//for循环中处理完所有子目录中的lua文件打包.下面把根目录的lua文件都打包到lua.unity3d文件中 AddBuildMap("lua/lua" + AppConst.ExtName, "*.bytes", "Assets/" + AppConst.LuaTempDir); //-------------------------------处理非Lua文件---------------------------------- string luaPath = pNowResPath + "/lua/";//AppDataPath + "/StreamingAssets/lua/"; for (int i = 0; i < srcDirs.Length; i++) { paths.Clear(); files.Clear(); string luaDataPath = srcDirs[i].ToLower(); Recursive(luaDataPath); foreach (string f in files) { if (f.EndsWith(".meta") || f.EndsWith(".lua")) { continue; } string newfile = f.Replace(luaDataPath, ""); string path = Path.GetDirectoryName(luaPath + newfile); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } //先拷贝lua相关目录下非Lua文件到StreamingAssets/lua/文件夹 string destfile = path + "/" + Path.GetFileName(f); File.Copy(f, destfile, true); } } AssetDatabase.Refresh(); }
static void HandleLuaBundle(ref List <AssetBundleBuild> buildList) { // �Ȱ�lua�ļ���������ʱĿ¼ string tempLuaDir = Application.dataPath + tempLua; if (!Directory.Exists(tempLuaDir)) { Directory.CreateDirectory(tempLuaDir); } string[] srcDirs = { Application.dataPath + "/Lua", Application.dataPath + "/ToLua/Lua" }; for (int i = 0; i < srcDirs.Length; i++) { if (LuaConst.LuaByteMode) { string sourceDir = srcDirs[i]; string[] files = Directory.GetFiles(sourceDir, "*.lua", SearchOption.AllDirectories); int len = sourceDir.Length; if (sourceDir[len - 1] == '/' || sourceDir[len - 1] == '\\') { --len; } for (int j = 0; j < files.Length; j++) { string str = files[j].Remove(0, len); string dest = tempLuaDir + str + ".bytes"; string dir = Path.GetDirectoryName(dest); Directory.CreateDirectory(dir); EncodeLuaFile(files[j], dest); } } else { ToLuaMenu.CopyLuaBytesFiles(srcDirs[i], tempLuaDir); } } // ����ʱĿ¼��ÿ�����ļ��е�lua���ļ��д�� string[] dirs = Directory.GetDirectories(tempLuaDir, "*", SearchOption.AllDirectories); for (int i = 0; i < dirs.Length; i++) { string name = dirs[i].Replace(tempLuaDir, string.Empty); name = name.Replace('\\', '_').Replace('/', '_'); name = "lua/lua_" + name.ToLower() + ".unity3d"; string path = "Assets" + dirs[i].Replace(Application.dataPath, ""); AddBuildMap(ref buildList, name, "*.bytes", path); } // ����ʱĿ¼������lua��һ���� AddBuildMap(ref buildList, "lua/lua" + ".unity3d", "*.bytes", "Assets" + tempLua); //-------------------------------�����Lua�ļ�---------------------------------- string luaTargetPath = AppDataPath + "/StreamingAssets/lua/"; for (int i = 0; i < srcDirs.Length; i++) { string luaDataPath = srcDirs[i].ToLower(); List <string> paths = new List <string>(); List <string> files = new List <string>(); Recursive(luaDataPath, ref paths, ref files); foreach (string f in files) { if (f.EndsWith(".meta") || f.EndsWith(".lua")) { continue; } string newfile = f.Replace(luaDataPath, ""); string destPath = Path.GetDirectoryName(luaTargetPath + newfile); if (!Directory.Exists(destPath)) { Directory.CreateDirectory(destPath); } string destfile = destPath + "/" + Path.GetFileName(f); File.Copy(f, destfile, true); } } AssetDatabase.Refresh(); }
/// <summary> /// 处理Lua代码包 /// </summary> private static void HandleLuaBundle() { string tempDir = Application.dataPath + "/" + LuaTempDir; if (!Directory.Exists(tempDir)) { Directory.CreateDirectory(tempDir); } string[] srcDirs = { CustomSettings.luaDir, CustomSettings.baseLuaDir }; for (int node = 0; node < srcDirs.Length; node++) { if (GameConst.LuaByteMode) { string sourceDir = srcDirs[node]; string[] files = Directory.GetFiles(sourceDir, "*.lua", SearchOption.AllDirectories); int len = sourceDir.Length; if (sourceDir[len - 1] == '/' || sourceDir[len - 1] == '\\') { --len; } for (int repo = 0; repo < files.Length; repo++) { string str = files[repo].Remove(0, len); string dest = tempDir + str + ".bytes"; string dir = Path.GetDirectoryName(dest); Directory.CreateDirectory(dir); EncodeLuaFile(files[repo], dest); } } else { ToLuaMenu.CopyLuaBytesFiles(srcDirs[node], tempDir); } } string[] dirs = Directory.GetDirectories(tempDir, "*", SearchOption.AllDirectories); for (int node = 0; node < dirs.Length; node++) { string name = dirs[node].Replace(tempDir, string.Empty); name = name.Replace('\\', '_').Replace('/', '_'); name = "lua/lua_" + name.ToLower() + GameConst.BundleSuffix; string path = "Assets" + dirs[node].Replace(Application.dataPath, ""); AddBuildMap(name, "*.bytes", path); } AddBuildMap("lua/lua" + GameConst.BundleSuffix, "*.bytes", "Assets/" + LuaTempDir); //-------------------------------处理非Lua文件---------------------------------- string luaPath = Application.dataPath + "/StreamingAssets/lua/"; for (int node = 0; node < srcDirs.Length; node++) { mPaths.Clear(); mFiles.Clear(); string luaDataPath = srcDirs[node].ToLower(); Recursive(luaDataPath); foreach (string file in mFiles) { if (file.EndsWith(".meta") || file.EndsWith(".lua")) { continue; } string newfile = file.Replace(luaDataPath, ""); string path = Path.GetDirectoryName(luaPath + newfile); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string destfile = path + "/" + Path.GetFileName(file); File.Copy(file, destfile, true); } } AssetDatabase.Refresh(); }
/// <summary> /// 处理Lua代码包 /// </summary> static void HandleLuaBundle() { //程序路径下创建一个临时目录LuaTempDir string streamDir = Application.dataPath + "/" + AppConst.LuaTempDir; if (!Directory.Exists(streamDir)) { Directory.CreateDirectory(streamDir); } //CustomSettings.luaDir = "Assets\LuaFramework\Lua" CustomSettings.FrameworkPat = "Assets\LuaFramework" string[] srcDirs = { CustomSettings.luaDir, CustomSettings.FrameworkPath + "/ToLua/Lua" }; //将 srcDirs 内容 复制到 streamDir(注意:要保证目录内的lua文件不重名,不然会造成覆盖) for (int i = 0; i < srcDirs.Length; i++) { //使用的是lua字节码的情况下 if (AppConst.LuaByteMode) { string sourceDir = srcDirs[i]; //获取目录下所有文件名称 string[] files = Directory.GetFiles(sourceDir, "*.lua", SearchOption.AllDirectories); int len = sourceDir.Length; if (sourceDir[len - 1] == '/' || sourceDir[len - 1] == '\\') { --len; } for (int j = 0; j < files.Length; j++) { string str = files[j].Remove(0, len); //生成目标路径 string dest = streamDir + str + ".bytes"; //返回dest的目录信息 string dir = Path.GetDirectoryName(dest); //创建目录和子目录 Directory.CreateDirectory(dir); //通过源文件生成目标文件lua字节码 EncodeLuaFile(files[j], dest); } } else { //将 lua 和 ToLua 内容复制到 streamDir 下 ToLuaMenu.CopyLuaBytesFiles(srcDirs[i], streamDir); } } //获取所有路径名字 //将每个路径下的所有lua文件合并成一个AssetBundleBuild 映射 string[] dirs = Directory.GetDirectories(streamDir, "*", SearchOption.AllDirectories); for (int i = 0; i < dirs.Length; i++) { string name = dirs[i].Replace(streamDir, string.Empty); name = name.Replace('\\', '_').Replace('/', '_'); name = "lua/lua_" + name.ToLower() + AppConst.ExtName; string path = "Assets" + dirs[i].Replace(Application.dataPath, ""); AddBuildMap(name, "*.bytes", path); } AddBuildMap("lua/lua" + AppConst.ExtName, "*.bytes", "Assets/" + AppConst.LuaTempDir); //-------------------------------处理非Lua文件---------------------------------- string luaPath = AppDataPath + "/StreamingAssets/lua/"; for (int i = 0; i < srcDirs.Length; i++) { paths.Clear(); files.Clear(); string luaDataPath = srcDirs[i].ToLower(); //递归找到所有的文件名和文件路径 Recursive(luaDataPath); //将文件移动到StreamingAssets/lua/的相应文件夹目录下 foreach (string f in files) { if (f.EndsWith(".meta") || f.EndsWith(".lua")) { continue; } string newfile = f.Replace(luaDataPath, ""); string path = Path.GetDirectoryName(luaPath + newfile); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string destfile = path + "/" + Path.GetFileName(f); File.Copy(f, destfile, true); } } AssetDatabase.Refresh(); }