/// <summary> /// Creates the streaming crc list. /// </summary> /// <param name="sb">Sb.</param> public static uint CreateStreamingCrcList(StringBuilder sb, string outPath = null) { var crc32filename = CUtils.GetAssetName(Common.CRC32_FILELIST_NAME); string tmpPath = BuildScript.GetAssetTmpPath();// Path.Combine(Application.dataPath, BuildScript.TmpPath); ExportResources.CheckDirectory(tmpPath); string assetPath = "Assets/" + BuildScript.TmpPath + crc32filename + ".txt"; EditorUtility.DisplayProgressBar("Generate streaming crc file list", "write file to " + assetPath, 0.99f); string outTmpPath = Path.Combine(tmpPath, crc32filename + ".txt"); using (StreamWriter sr = new StreamWriter(outTmpPath, false)) { sr.Write(sb.ToString()); } // //打包到streaming path AssetDatabase.Refresh(); string crc32outfilename = CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME); Debug.Log("write to path=" + outPath); Debug.Log(sb.ToString()); //读取crc string abPath = string.Empty; if (string.IsNullOrEmpty(outPath)) { abPath = Path.Combine(CUtils.realStreamingAssetsPath, crc32outfilename); } else { abPath = Path.Combine(outPath, crc32outfilename); } BuildScript.BuildABs(new string[] { assetPath }, outPath, crc32outfilename, BuildAssetBundleOptions.DeterministicAssetBundle); CrcCheck.Clear(); uint fileCrc = CrcCheck.GetLocalFileCrc(abPath); EditorUtility.ClearProgressBar(); Debug.Log("Crc file list assetbunle build complate! " + fileCrc.ToString() + abPath); if (!string.IsNullOrEmpty(outPath)) { string newName = Path.Combine(outPath, CUtils.InsertAssetBundleName(crc32outfilename, "_" + fileCrc.ToString())); FileInfo finfo = new FileInfo(abPath); finfo.MoveTo(newName); Debug.Log(" change name to " + newName); } return(fileCrc); }
public static void exportConfig() { var files = AssetDatabase.GetAllAssetPaths().Where(p => p.StartsWith("Assets/Config") && p.EndsWith(".csv") ).ToArray(); BuildScript.CheckstreamingAssetsPath(); string cname = CUtils.GetRightFileName(Common.CONFIG_CSV_NAME); BuildScript.BuildABs(files.ToArray(), null, cname, BuildAssetBundleOptions.DeterministicAssetBundle); Debug.Log(" Config export " + cname); }
public static void exportLanguage() { string assetPath = "Assets/Lan/"; var files = AssetDatabase.GetAllAssetPaths().Where(p => p.StartsWith(assetPath) && p.EndsWith(".csv") ).ToArray(); BuildScript.CheckstreamingAssetsPath(); foreach (string abPath in files) { string name = CUtils.GetAssetName(abPath); string abName = CUtils.GetRightFileName(name + "." + Common.LANGUAGE_SUFFIX); BuildScript.BuildABs(new string[] { abPath }, null, abName, BuildAssetBundleOptions.CompleteAssets); Debug.Log(name + " " + abName + " export"); } }
public static void exportLua() { checkLuaExportPath(); BuildScript.CheckstreamingAssetsPath(); string info = "luac"; string title = "build lua"; EditorUtility.DisplayProgressBar(title, info, 0); var childrens = AssetDatabase.GetAllAssetPaths().Where(p => (p.StartsWith("Assets/Lua") || p.StartsWith("Assets/Config")) && (p.EndsWith(".lua")) ).ToArray(); string path = "Assets/Lua/"; //lua path string path1 = "Assets/Config/"; //config path string root = Application.dataPath.Replace("Assets", ""); Debug.Log("luajit path = " + luacPath); string crypName = "", fileName = "", outfilePath = "", arg = ""; System.Text.StringBuilder sb = new System.Text.StringBuilder(); //refresh directory DirectoryDelete(Application.dataPath + OutLuaPath); CheckDirectory(Application.dataPath + OutLuaPath); float allLen = childrens.Length; float i = 0; List <string> exportNames = new List <string>(); foreach (string file in childrens) { string filePath = Path.Combine(root, file); fileName = CUtils.GetAssetName(filePath); crypName = file.Replace(path, "").Replace(path1, "").Replace(".lua", "." + Common.LUA_LC_SUFFIX).Replace("\\", "_").Replace("/", "_"); outfilePath = Application.dataPath + OutLuaPath + crypName; exportNames.Add("Assets" + OutLuaPath + crypName); sb.Append(fileName); sb.Append("="); sb.Append(crypName); sb.Append("\n"); #if Nlua || UNITY_IPHONE arg = "-o " + outfilePath + " " + filePath; // luac File.Copy(filePath, outfilePath, true); // source code copy #else arg = "-b " + filePath + " " + outfilePath; //for jit //Debug.Log(arg); //System.Diagnostics.Process.Start(luacPath, arg);//jit File.Copy(filePath, outfilePath, true);// source code copy #endif i++; EditorUtility.DisplayProgressBar(title, info + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen); } Debug.Log("lua:" + path + "files=" + childrens.Length + " completed"); System.Threading.Thread.Sleep(1000); AssetDatabase.Refresh(); EditorUtility.DisplayProgressBar(title, "build lua", 0.99f); //u5 打包 CheckDirectory(Path.Combine(Application.dataPath, OutLuaPath)); BuildScript.BuildABs(exportNames.ToArray(), "Assets" + OutLuaPath, "luaout.bytes", BuildAssetBundleOptions.DeterministicAssetBundle); EditorUtility.DisplayProgressBar(title, "Encrypt lua", 0.99f); //Encrypt string tarName = Application.dataPath + OutLuaPath + "luaout.bytes"; string md5Name = CUtils.GetRightFileName(Common.LUA_ASSETBUNDLE_FILENAME); string realOutPath = Path.Combine(BuildScript.GetOutPutPath(), md5Name); byte[] by = File.ReadAllBytes(tarName); byte[] Encrypt = CryptographHelper.Encrypt(by, GetKey(), GetIV()); File.WriteAllBytes(realOutPath, Encrypt); Debug.Log(realOutPath + " export"); EditorUtility.ClearProgressBar(); }
public static void GenerateAssetBundlesUpdateFile(string[] allBundles) { string title = "Generate Update File "; string info = "Compute crc32"; EditorUtility.DisplayProgressBar(title, info, 0.1f); #region 读取首包 CrcCheck.Clear(); bool firstExists = false; DirectoryInfo firstDir = new DirectoryInfo(Application.dataPath); string firstPath = Path.Combine(firstDir.Parent.Parent.FullName, Common.FirstOutPath); string readPath = Path.Combine(firstPath, CUtils.GetAssetPath("")); readPath = Path.Combine(readPath, CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME)); Debug.Log(readPath); WWW abload = new WWW("file://" + readPath); if (string.IsNullOrEmpty(abload.error) && abload.assetBundle != null) { var ab = abload.assetBundle; TextAsset ta = ab.LoadAllAssets <TextAsset>()[0]; //ta.text Debug.Log(ta); string context = ta.text; string[] split = context.Split('\n'); System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"\[""(.+)""\]\s+=\s+(\d+)"); float j = 1; float l = split.Length; foreach (var line in split) { System.Text.RegularExpressions.Match match = regex.Match(line); if (match.Success) { //Debug.Log(match.Groups[1].Value + " " + match.Groups[2].Value); CrcCheck.Add(match.Groups[1].Value, System.Convert.ToUInt32(match.Groups[2].Value)); } //Debug.Log(line); EditorUtility.DisplayProgressBar(title, "read first crc => " + j.ToString() + "/" + l.ToString(), j / l); j++; } ab.Unload(true); firstExists = true; } else { Debug.LogWarning(abload.error + "no frist packeage in " + readPath); } abload.Dispose(); #endregion #region 生成校验列表 Dictionary <string, uint> updateList = new Dictionary <string, uint>(); StringBuilder sb = new StringBuilder(); sb.AppendLine("return {"); var selected = string.Empty; float i = 0; float allLen = allBundles.Length; //忽略列表 Dictionary <string, bool> ignore = new Dictionary <string, bool>(); ignore.Add(CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME), true); ignore.Add(CUtils.GetRightFileName(Common.CRC32_VER_FILENAME), true); foreach (var str in allBundles) { string url = Path.Combine(CUtils.GetRealStreamingAssetsPath(), str); uint outCrc = 0; Debug.Log(str); string abName = str.Replace("\\", "/"); string key = CUtils.GetAssetBundleName(abName); if (!ignore.ContainsKey(key) && CrcCheck.CheckLocalFileWeakCrc(url, out outCrc) == false) //如果不一致需要更新 { updateList.Add(abName, outCrc); //记录导出记录 sb.AppendLine("[\"" + key + "\"] = " + outCrc + ","); } EditorUtility.DisplayProgressBar(title, info + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen); i++; } sb.AppendLine("}"); //Debug.Log (sb.ToString ()); CrcCheck.Clear(); //输出到临时目录 var crc32filename = CUtils.GetAssetName(Common.CRC32_FILELIST_NAME); string tmpPath = Path.Combine(Application.dataPath, TmpPath); ExportResources.CheckDirectory(tmpPath); string assetPath = "Assets/" + TmpPath + crc32filename + ".txt"; EditorUtility.DisplayProgressBar("Generate file list", "write file to " + assetPath, 0.99f); string outPath = Path.Combine(tmpPath, crc32filename + ".txt"); Debug.Log("write to path=" + outPath); using (StreamWriter sr = new StreamWriter(outPath, false)) { sr.Write(sb.ToString()); } // //打包到streaming path AssetDatabase.Refresh(); string crc32outfilename = CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME); //(fileCrc32ListName + ".u3d"); BuildScript.BuildABs(new string[] { assetPath }, null, crc32outfilename, BuildAssetBundleOptions.DeterministicAssetBundle); string topath = Path.Combine(GetOutPutPath(), crc32outfilename); Debug.Log(info + " assetbunle build complate! " + topath); #endregion #region 生成版本号 //生成版本号码 string crc32Path = "file://" + Path.Combine(CUtils.GetRealStreamingAssetsPath(), CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME)); //CUtils.GetAssetFullPath (fileCrc32ListName+".u3d"); WWW loaderVer = new WWW(crc32Path); if (!string.IsNullOrEmpty(loaderVer.error)) { Debug.LogError(loaderVer.error); return; } uint crcVer = Crc32.Compute(loaderVer.bytes); loaderVer.Dispose(); tmpPath = CUtils.GetRealStreamingAssetsPath();//Path.Combine (Application.streamingAssetsPath, CUtils.GetAssetPath("")); outPath = Path.Combine(tmpPath, CUtils.GetRightFileName(Common.CRC32_VER_FILENAME)); Debug.Log("verion to path=" + outPath); //json 化version{ code,crc32,version} StringBuilder verJson = new StringBuilder(); verJson.Append("{"); verJson.Append(@"""code"":" + CodeVersion.CODE_VERSION + ","); verJson.Append(@"""crc32"":" + crcVer.ToString() + ","); verJson.Append(@"""time"":" + CUtils.ConvertDateTimeInt(System.DateTime.Now) + ""); verJson.Append("}"); using (StreamWriter sr = new StreamWriter(outPath, false)) { sr.Write(verJson.ToString()); } Debug.Log(info + " Complete! ver=" + crcVer.ToString() + " path " + outPath); BuildScript.BuildAssetBundles(); #endregion #region copy更新文件导出 if (updateList.Count > 0) { info = "copy updated file "; string updateOutPath = Path.Combine(firstPath, CUtils.GetAssetPath("") + System.DateTime.Now.ToString("_yyyy-MM-dd_HH-mm")); DirectoryInfo outDic = new DirectoryInfo(updateOutPath); if (outDic.Exists) { outDic.Delete(); } outDic.Create(); if (!firstExists) { updateList.Clear(); //如果没有首包,只导出校验文件。 } updateList.Add(CUtils.GetRightFileName(Common.CRC32_VER_FILENAME), 0); updateList.Add(CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME), crcVer); string sourcePath; string outfilePath; i = 1; allLen = updateList.Count; string key = ""; foreach (var k in updateList) { key = CUtils.GetAssetBundleName(k.Key); sourcePath = Path.Combine(CUtils.GetRealStreamingAssetsPath(), k.Key); if (k.Value != 0) { if (key.Equals(CUtils.platformFloder)) { key = key + "_" + k.Value.ToString() + "." + Common.ASSETBUNDLE_SUFFIX; } else { key = CUtils.InsertAssetBundleName(key, "_" + k.Value.ToString());// } } outfilePath = Path.Combine(updateOutPath, key); FileHelper.CheckCreateFilePathDirectory(outfilePath); File.Copy(sourcePath, outfilePath, true);// source code copy EditorUtility.DisplayProgressBar(title, info + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen); i++; } Debug.Log(" copy file complete!"); } #endregion EditorUtility.ClearProgressBar(); }