public static void SetAssetbundleBinaryTxt() { AssetBundleBinary dependency = new AssetBundleBinary(); dependency.path = AppConst.AssetDir; dependency.guidName = dependency.path; dependency.isExtension = false; mAllAbFiles.Add(dependency); FileStream fs = new FileStream(BuildTargetPath + "abFile.txt", FileMode.Create); StreamWriter sw = new StreamWriter(fs); for (int i = 0; i < mAllAbFiles.Count; ++i) { if (mAllAbFiles[i].isExtension) { mAllAbFiles[i].fileMd5 = Util.md5file(BuildTargetPath + mAllAbFiles[i].guidName + ".unity3d"); } else { mAllAbFiles[i].fileMd5 = Util.md5file(BuildTargetPath + mAllAbFiles[i].guidName); } sw.WriteLine(string.Format("{0}|{1}|{2}", mAllAbFiles[i].guidName, mAllAbFiles[i].fileMd5, mAllAbFiles[i].path)); } sw.Close(); fs.Close(); }
/// <summary> /// /// </summary> /// <param name="filePath">文件路径</param> /// <param name="abNamePath">表示文件所在文件路径的根文件目录,用于将这个参数下的所有文件打包成一个ab</param> /// <param name="abAssetName">指定使用此参数作为ab名称</param> static public void setAssetBundleName(string filePath, string abNamePath = "", string abAssetName = "") { string abName = abAssetName; bool isAbAssetName = false; if (abName == "") { Object obj = AssetDatabase.LoadMainAssetAtPath(filePath); if (obj.GetType() == typeof(Shader)) { setAssetBundleName(filePath, "", _shaderAbName); return; } if (abNamePath != "") { abName = abNamePath.Replace("\\", "/"); isAbAssetName = true; } else { abName = filePath; } if (abName.StartsWith(BuildSrcPath)) { abName = abName.Substring(BuildSrcPath.Length + 1); } else { abName = abName.Substring(("Assets").Length + 1);// 这个不是打包文件夹内内容 } abName = abName.Replace("/", "$"); } else { isAbAssetName = true; } if (_IsMd5) { AssetBundleBinary info = new AssetBundleBinary(); info.path = abName + ".unity3d"; if (isAbAssetName) { abName = Util.md5(abName); } else { abName = AssetDatabase.AssetPathToGUID(filePath); abName = Util.md5(abName); } info.guidName = abName; if (mAllAbFiles.Find((p) => { return(p.guidName == info.guidName); }) == null) { mAllAbFiles.Add(info); } } abName += ".unity3d"; AssetImporter importer = AssetImporter.GetAtPath(filePath); if (importer.assetBundleName.CompareTo(abName) != 0) { importer.assetBundleName = abName; //importer.SaveAndReimport(); } }