public static void DoExport() { var files = AssetDatabase.GetAllAssetPaths().Where(p => p.StartsWith("Assets/Lua/proto") && (p.EndsWith(".proto") || p.EndsWith(".pb")) ).ToArray(); //copy EditorUtils.CheckstreamingAssetsPath(); string OutLuaProtobufPath = GetLuaProtobufResourcesPath(); AssetDatabase.DeleteAsset(OutLuaProtobufPath); GetLuaProtobufResourcesPath(); var dests = new string[files.Length]; System.Text.StringBuilder sb = new System.Text.StringBuilder(); for (int i = 0; i < files.Length; i++) { string xfile = System.IO.Path.GetFileName(files[i]);//.Remove(0, rootPath.Length + 1); string file = files[i].Replace("\\", "/"); string dest = OutLuaProtobufPath + "/" + CUtils.GetRightFileName(xfile).Replace(".", "+"); string destName = dest + ".bytes"; dests[i] = destName; Debug.LogFormat("Copy({0},{1})", file, destName); System.IO.File.Copy(file, destName, true); sb.AppendFormat("\r\n {0} ({1}) ", file, destName); } string tmpPath = EditorUtils.GetAssetTmpPath(); EditorUtils.CheckDirectory(tmpPath); string outPath = Path.Combine(tmpPath, "lua_protobuf_export_log.txt"); Debug.Log("write to path=" + outPath); using (StreamWriter sr = new StreamWriter(outPath, false)) { sr.Write(sb.ToString()); } EditorUtility.ClearProgressBar(); AssetDatabase.Refresh(); //addressables var setting = AASEditorUtility.LoadAASSetting(); var groupSchama = AASEditorUtility.DefaltGroupSchema[0]; var group = AASEditorUtility.FindGroup(LUA_PROTO_GROUP_NAME, groupSchama);//setting.FindGroup(LUA_GROUP_NAME); foreach (var str in dests) { var guid = AssetDatabase.AssetPathToGUID(str); //获得GUID var entry = setting.CreateOrMoveEntry(guid, group); //通过GUID创建entry entry.SetAddress(System.IO.Path.GetFileNameWithoutExtension(str)); entry.SetLabel("lua_protobuf", true); } }
public static void DoExportLua(string rootPath) { EditorUtils.CheckstreamingAssetsPath(); string OutLuaBytesPath = GetLuaBytesResourcesPath(); AssetDatabase.DeleteAsset(OutLuaBytesPath); GetLuaBytesResourcesPath(); System.Text.StringBuilder sb = new System.Text.StringBuilder(); var files = Directory.GetFiles(rootPath, "*.lua", SearchOption.AllDirectories); var dests = new string[files.Length]; for (int i = 0; i < files.Length; i++) { string xfile = files[i].Remove(0, rootPath.Length + 1); xfile = "lua_" + xfile.Replace("\\", "+").Replace("/", "+"); string file = files[i].Replace("\\", "/"); string dest = OutLuaBytesPath + "/" + CUtils.GetRightFileName(xfile); string destName = dest.Substring(0, dest.Length - 3) + "bytes"; dests[i] = destName; System.IO.File.Copy(file, destName, true); sb.AppendFormat("\r\n {0} ({1}) ", file, destName); } string tmpPath = EditorUtils.GetAssetTmpPath(); EditorUtils.CheckDirectory(tmpPath); string outPath = Path.Combine(tmpPath, "lua_export_log.txt"); Debug.Log("write to path=" + outPath); using (StreamWriter sr = new StreamWriter(outPath, false)) { sr.Write(sb.ToString()); } EditorUtility.ClearProgressBar(); AssetDatabase.Refresh(); //addressables var setting = AASEditorUtility.LoadAASSetting(); var groupSchama = AASEditorUtility.DefaltGroupSchema[0]; var group = AASEditorUtility.FindGroup(LUA_GROUP_NAME, groupSchama); //setting.FindGroup(LUA_GROUP_NAME); AASEditorUtility.ClearGroup(LUA_GROUP_NAME); //清空 foreach (var str in dests) { var guid = AssetDatabase.AssetPathToGUID(str); //获得GUID var entry = setting.CreateOrMoveEntry(guid, group); //通过GUID创建entry entry.SetAddress(System.IO.Path.GetFileNameWithoutExtension(str)); entry.SetLabel("lua_script", true); } }
public static uint CreateStreamingFileManifest(AssetBundleManifest assetBundleManifest) { var allABs = assetBundleManifest.GetAllAssetBundles(); var bundlesWithVariant = assetBundleManifest.GetAllAssetBundlesWithVariant(); var streamingManifest = ScriptableObject.CreateInstance(typeof(FileManifest)) as FileManifest; //读取 bundlesWithVariant var MyVariant = new string[bundlesWithVariant.Length]; for (int i = 0; i < bundlesWithVariant.Length; i++) { var curSplit = bundlesWithVariant[i].Split('.'); MyVariant[i] = bundlesWithVariant[i]; } //读取abinfo List <ABInfo> allABInfos = new List <ABInfo>(); foreach (var abs in allABs) { var abInfo = new ABInfo(abs, 0, 0, 0); var dependencies = assetBundleManifest.GetAllDependencies(abs); abInfo.dependencies = dependencies; allABInfos.Add(abInfo); } //fill data streamingManifest.allAbInfo = allABInfos; streamingManifest.allAssetBundlesWithVariant = bundlesWithVariant; streamingManifest.appNumVersion = CodeVersion.APP_NUMBER; streamingManifest.newAppNumVersion = CodeVersion.APP_NUMBER; streamingManifest.version = CodeVersion.APP_VERSION; //create asset string tmpPath = EditorUtils.GetAssetTmpPath();// Path.Combine(Application.dataPath, BuildScript.TmpPath); EditorUtils.CheckDirectory(tmpPath); var crc32filename = CUtils.GetAssetName(Common.CRC32_FILELIST_NAME); string assetPath = "Assets/" + EditorUtils.TmpPath + crc32filename + ".asset"; AssetDatabase.CreateAsset(streamingManifest, assetPath); //build assetbundle string crc32outfilename = CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME); BuildScript.BuildABs(new string[] { assetPath }, null, crc32outfilename, DefaultBuildAssetBundleOptions); streamingManifest.WriteToFile("Assets/" + EditorUtils.TmpPath + "BuildStreamingAssetsManifest.txt"); Debug.LogFormat("FileManifest Path = {0}/{1};", CUtils.realStreamingAssetsPath, crc32outfilename); return(0); }
public static void doExportLua(string rootPath) { EditorUtils.CheckstreamingAssetsPath(); string OutLuaBytesPath = EditorUtils.GetLuaBytesResourcesPath(); AssetDatabase.DeleteAsset(OutLuaBytesPath); EditorUtils.GetLuaBytesResourcesPath(); System.Text.StringBuilder sb = new System.Text.StringBuilder(); var files = Directory.GetFiles(rootPath, "*.lua", SearchOption.AllDirectories); var dests = new string[files.Length]; // var dests64 = new string[files.Length]; for (int i = 0; i < files.Length; i++) { string xfile = files[i].Remove(0, rootPath.Length + 1); xfile = xfile.Replace("\\", "+").Replace("/", "+"); string file = files[i].Replace("\\", "/"); string dest = OutLuaBytesPath + "/" + CUtils.GetRightFileName(xfile); string destName = dest.Substring(0, dest.Length - 3) + "bytes"; System.IO.File.Copy(file, destName, true); sb.AppendFormat("\r\n {0} ({1}) ", file, destName); } string tmpPath = EditorUtils.GetAssetTmpPath(); EditorUtils.CheckDirectory(tmpPath); string outPath = Path.Combine(tmpPath, "lua_export_log.txt"); Debug.Log("write to path=" + outPath); using (StreamWriter sr = new StreamWriter(outPath, false)) { sr.Write(sb.ToString()); } EditorUtility.ClearProgressBar(); }
public static void exportLuaProtobuf() { var files = AssetDatabase.GetAllAssetPaths().Where(p => p.StartsWith("Assets/Lua/proto") && (p.EndsWith(".proto") || p.EndsWith(".pb")) ).ToArray(); //copy EditorUtils.CheckstreamingAssetsPath(); string OutLuaProtobufPath = EditorUtils.GetLuaProtobufResourcesPath(); AssetDatabase.DeleteAsset(OutLuaProtobufPath); EditorUtils.GetLuaProtobufResourcesPath(); System.Text.StringBuilder sb = new System.Text.StringBuilder(); for (int i = 0; i < files.Length; i++) { string xfile = System.IO.Path.GetFileName(files[i]);//.Remove(0, rootPath.Length + 1); string file = files[i].Replace("\\", "/"); string dest = OutLuaProtobufPath + "/" + CUtils.GetRightFileName(xfile); string destName = dest + ".txt"; Debug.LogFormat("Copy({0},{1})", file, destName); System.IO.File.Copy(file, destName, true); sb.AppendFormat("\r\n {0} ({1}) ", file, destName); } string tmpPath = EditorUtils.GetAssetTmpPath(); EditorUtils.CheckDirectory(tmpPath); string outPath = Path.Combine(tmpPath, "lua_protobuf_export_log.txt"); Debug.Log("write to path=" + outPath); using (StreamWriter sr = new StreamWriter(outPath, false)) { sr.Write(sb.ToString()); } EditorUtility.ClearProgressBar(); }
private static void CopyFileToSplitFolder(Dictionary <string, ABInfo> updateList) { string updateOutPath = Path.Combine(UpdateOutPath, ResFolderName); //总的资源目录 // ExportResources.CheckDirectory(updateOutPath); string verPath = Path.Combine(UpdateOutVersionPath, ResFolderName); //特定版本资源目录用于资源备份 // ExportResources.CheckDirectory(verPath); int allLen = updateList.Count; int i = 0; Debug.LogFormat("CopyFileToSplitFolder.Count = {0}", updateList.Count); EditorUtility.DisplayProgressBar("Copy Change AssetBundle File", "copy file to " + updateOutPath + updateList.Count, 0.09f); string sourcePath; string outfilePath, outfileVerionPath; string key, extension; uint crc = 0; StringBuilder erro = new StringBuilder(); foreach (var k in updateList) { key = k.Key;//CUtils.GetAssetBundleName(k.Key); // Debug.LogFormat(" update file = {0},{1},{2};", k.Key, k.Value.abName, k.Value.assetPath); if (string.IsNullOrEmpty(k.Value.assetPath)) { continue; } sourcePath = Path.Combine(Application.dataPath, k.Value.assetPath); if (!File.Exists(sourcePath)) // { string e = string.Format("copy file ({0}) not Exists ", sourcePath); Debug.LogWarning(e); erro.AppendLine(e); continue; } extension = System.IO.Path.GetExtension(key); crc = (uint)k.Value.crc32; if (crc != 0) { if (string.IsNullOrEmpty(extension)) { key = EditorUtils.InsertAssetBundleName(key + Common.CHECK_ASSETBUNDLE_SUFFIX, "_" + crc.ToString()); } else if (extension == Common.DOT_BYTES) { key = key.Replace(extension, Common.CHECK_ASSETBUNDLE_SUFFIX); key = EditorUtils.InsertAssetBundleName(key, "_" + crc.ToString());// } else { key = EditorUtils.InsertAssetBundleName(key, "_" + crc.ToString());// } } outfilePath = Path.Combine(updateOutPath, key); outfileVerionPath = Path.Combine(verPath, key); // Debug.LogFormat("{0} copy to {1}", outfilePath, outfileVerionPath); // uint filelen = 0; uint copyFileCrc = 0; // var resType = HugulaSetting.instance.backupResType; // if (resType == CopyResType.VerResFolder) // { FileHelper.CheckCreateFilePathDirectory(outfileVerionPath); File.Copy(sourcePath, outfileVerionPath, true); // copy to v{d}/res folder copyFileCrc = CrcCheck.GetLocalFileCrc(outfileVerionPath, out filelen); // } // if (resType == CopyResType.OneResFolder) // { // FileHelper.CheckCreateFilePathDirectory(outfilePath); // File.Copy(sourcePath, outfilePath, true);// copy to /res folder // copyFileCrc = CrcCheck.GetLocalFileCrc(outfilePath, out filelen); // } //check file crc if (copyFileCrc != crc) { string e = string.Format("crc(source{0}!=copy{1}),path={2}", crc, copyFileCrc, outfilePath); Debug.LogError(e); erro.AppendLine(e); } EditorUtility.DisplayProgressBar("copy file to split folder " + updateOutPath, " copy file =>" + i.ToString() + "/" + allLen.ToString(), i / allLen); i++; } Debug.Log(" copy file complete!"); EditorUtility.ClearProgressBar(); string errContent = erro.ToString(); if (!string.IsNullOrEmpty(errContent)) { string tmpPath = EditorUtils.GetAssetTmpPath(); EditorUtils.CheckDirectory(tmpPath); string outPath = Path.Combine(tmpPath, "error.txt"); Debug.Log("write to path=" + outPath); using (StreamWriter sr = new StreamWriter(outPath, true)) { sr.WriteLine(" Error : " + System.DateTime.Now.ToString()); sr.Write(errContent); } } }
/// <summary> /// Creates the streaming crc list. /// </summary> /// <param name="sb">Sb.</param> public static uint CreateStreamingCrcList(FileManifest sb, string fileListName, bool firstExists = false, bool copyToResFolder = false) { sb.appNumVersion = CodeVersion.APP_NUMBER; sb.newAppNumVersion = CodeVersion.APP_NUMBER; sb.version = CodeVersion.APP_VERSION; var crc32filename = CUtils.GetAssetName(fileListName); string tmpPath = EditorUtils.GetAssetTmpPath();// Path.Combine(Application.dataPath, BuildScript.TmpPath); EditorUtils.CheckDirectory(tmpPath); string assetPath = "Assets/" + EditorUtils.TmpPath + crc32filename + ".asset"; EditorUtility.DisplayProgressBar("Generate streaming crc file list", "write file to " + assetPath, 0.99f); AssetDatabase.CreateAsset(sb, assetPath); string crc32outfilename = CUtils.GetRightFileName(fileListName); // Debug.Log("write to path=" + outPath); //读取crc string abPath = string.Empty; string resOutPath = null; uint fileSize = 0; uint fileCrc = 0; if (copyToResFolder) { resOutPath = tmpPath;//Path.Combine(tmpPath, ResFolderName); //Path.Combine(SplitPackage.UpdateOutPath, ResFolderName); abPath = Path.Combine(resOutPath, crc32outfilename); BuildScript.BuildABs(new string[] { assetPath }, resOutPath, crc32outfilename, DefaultBuildAssetBundleOptions); fileCrc = CrcCheck.GetLocalFileCrc(abPath, out fileSize); //copy crc list FileInfo finfo = new FileInfo(abPath); // var resType = HugulaSetting.instance.backupResType; // if (resType == CopyResType.VerResFolder) // { string verPath = Path.Combine(UpdateOutVersionPath, ResFolderName); //特定版本资源目录用于资源备份 string newName = Path.Combine(verPath, EditorUtils.InsertAssetBundleName(crc32outfilename, "_" + fileCrc.ToString())); FileHelper.CheckCreateFilePathDirectory(newName); if (File.Exists(newName)) { File.Delete(newName); } finfo.CopyTo(newName); // } // if (resType == CopyResType.OneResFolder) // { // string updateOutPath = Path.Combine(UpdateOutPath, ResFolderName);//总的资源目录 // string newName = Path.Combine(updateOutPath, EditorUtils.InsertAssetBundleName(crc32outfilename, "_" + fileCrc.ToString())); // FileHelper.CheckCreateFilePathDirectory(newName); // if (File.Exists(newName)) File.Delete(newName); // finfo.CopyTo(newName); // } } else { abPath = Path.Combine(CUtils.realStreamingAssetsPath, crc32outfilename); BuildScript.BuildABs(new string[] { assetPath }, null, crc32outfilename, DefaultBuildAssetBundleOptions); fileCrc = CrcCheck.GetLocalFileCrc(abPath, out fileSize); } // CrcCheck.Clear(); //copy first crc list if (!firstExists && File.Exists(abPath)) //如果没有首包 copy first package { string crc32FirstOutName = CUtils.InsertAssetBundleName(crc32outfilename, "_v" + CodeVersion.CODE_VERSION.ToString()); string destFirst = Path.Combine(UpdateOutPath, crc32FirstOutName); Debug.LogFormat("abpath={0},destFirst={1}:", abPath, destFirst); File.Copy(abPath, destFirst, true); } EditorUtility.ClearProgressBar(); // File.Delete(assetPath); Debug.Log("Crc file list assetbunle build complate! " + fileCrc.ToString() + abPath); return(fileCrc); }