static public int GetAssetPath_s(IntPtr l) { try { System.String a1; checkType(l, 1, out a1); var ret = CUtils.GetAssetPath(a1); pushValue(l, ret); return(1); } catch (Exception e) { LuaDLL.luaL_error(l, e.ToString()); return(0); } }
public static string GetOutPutPath() { return(Path.Combine(streamingPath, CUtils.GetAssetPath(""))); }
public static string GetFileStreamingOutAssetsPath() { string dircAssert = Path.Combine(Application.streamingAssetsPath, CUtils.GetAssetPath("")); return(dircAssert); }
public static void DeleteStreamingOutPath() { ExportResources.DirectoryDelete(Path.Combine(Application.streamingAssetsPath, CUtils.GetAssetPath(""))); }
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(); }
/// <summary> /// 1 读取首包,找出忽略文件 /// </summary> /// <param name="ignoreFiles">Ignore files.</param> public static bool ReadFirst(Dictionary <string, uint> firstCrcDict, HashSet <string> whiteFileList, HashSet <string> blackFileList) { string title = "read first crc file list"; CrcCheck.Clear(); bool firstExists = false; string readPath = Path.Combine(GetFirstOutPath(), CUtils.GetAssetPath("")); readPath = Path.Combine(readPath, CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME)); Debug.Log(readPath); whiteFileList.Clear(); blackFileList.Clear(); 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)); firstCrcDict.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(); //读取忽略扩展包 string firstStreamingPath = CUtils.realStreamingAssetsPath; DirectoryInfo dinfo = new DirectoryInfo(firstStreamingPath); var dircs = dinfo.GetDirectories(); foreach (var dir in dircs) { var u3dList = ExportResources.getAllChildFiles(dir.FullName, @"\.meta$|\.manifest$|\.DS_Store$", null, false); List <string> assets = new List <string>(); foreach (var s in u3dList) { string ab = CUtils.GetAssetBundleName(s); ab = ab.Replace("\\", "/"); blackFileList.Add(ab); Debug.Log("extends folder:" + ab); } } //从网络读取白名单列表 todo EditorUtility.ClearProgressBar(); return(firstExists); }