static void BuildAssetBundles() { var outputPath = ResKitUtil.BuildAssetBundleFullPath(string.Empty); if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } BuildPipeline.BuildAssetBundles(outputPath, BuildAssetBundleOptions.ChunkBasedCompression, EditorUserBuildSettings.activeBuildTarget); var versionConfigFilePath = outputPath + "/ResVersion.json"; List <string> AssetBundleMD5s = GetAssetBundleMD5s(outputPath); var resVersion = new ResVersion() { Version = HotUpdateStaticConfig.RemoteBundleVersion, AssetBundleNames = AssetDatabase.GetAllAssetBundleNames().Where(name => File.Exists(string.Format("{0}/{1}", outputPath, name)) && !HotUpdateStaticConfig.UnrecordBundleName.Contains(name)).ToList(), AssetBundleMD5s = AssetBundleMD5s }; var resVersionJson = JsonUtility.ToJson(resVersion, true); File.WriteAllText(versionConfigFilePath, resVersionJson); AssetDatabase.Refresh(); }
private ResVersion GetNeedDownloadResVersion(ResVersion remoteResVersion) { var needDownloadResVersion = new ResVersion(); for (int i = 0; i < remoteResVersion.AssetBundleNames.Count; i++) { var tmpBundlePath = string.Format("{0}{1}", Config.HotUpdateAssetBundlesFolder, remoteResVersion.AssetBundleNames[i]); if (File.Exists(tmpBundlePath)) { if (!FileMD5Tools.MD5Stream(tmpBundlePath).Equals(remoteResVersion.AssetBundleMD5s[i])) { File.Delete(tmpBundlePath); needDownloadResVersion.AssetBundleNames.Add(remoteResVersion.AssetBundleNames[i]); } else { Debug.Log("MD5相同,下一个"); } } else { needDownloadResVersion.AssetBundleNames.Add(remoteResVersion.AssetBundleNames[i]); } } return(needDownloadResVersion); }
private void Awake() { Config = HotUpdateStaticConfig.MgrAssetBundlesConfig; UpdatedResVersion = new ResVersion() { Version = 0, AssetBundleMD5s = new List <string>(), AssetBundleNames = new List <string>() }; }
private IEnumerator DoFullDownloadRes(ResVersion remoteResVersion, Action downloadDone) { //创建临时目录 if (!Directory.Exists(TempAssetBundlesPath)) { Directory.CreateDirectory(TempAssetBundlesPath); } var remoteBasePath = FullHotUpdateMgr.Instance.Config.RemoteAssetBundleURLBase; //补上 AssetBundleMenifest 文件 remoteResVersion.AssetBundleNames.Add(ResKitUtil.GetPlatformName()); for (int i = 0; i < remoteResVersion.AssetBundleNames.Count; i++) { string assetBundleName = remoteResVersion.AssetBundleNames[i]; UnityWebRequest uwr = UnityWebRequest.Get(string.Format("{0}/{1}", remoteBasePath, assetBundleName)); uwr.timeout = 5; uwr.SendWebRequest(); if (uwr.isHttpError || uwr.isNetworkError) { Debug.Log(uwr.error); //todo error处理 } else { while (!uwr.isDone) { var progress = uwr.downloadProgress; yield return(0); } if (uwr.isDone) //如果下载完成了 { Debug.Log("完成"); } var bytes = uwr.downloadHandler.data; var filepath = TempAssetBundlesPath + assetBundleName; File.WriteAllBytes(filepath, bytes); } } downloadDone(); }
private void DeleteUnusedBundle(ResVersion remoteResVersion) { if (!Directory.Exists(Config.HotUpdateAssetBundlesFolder)) { return; } var files = Directory.GetFiles(Config.HotUpdateAssetBundlesFolder); for (int i = 0; i < files.Length; i++) { var fileName = files[i].Substring(Config.HotUpdateAssetBundlesFolder.Length); if (!remoteResVersion.AssetBundleNames.Contains(fileName)) { File.Delete(files[i]); } } }
public void RecordClearAndGetDownLoadNames(ResVersion remoteResVersion, Action <List <string> > onResult) { //Record UpdatedResVersion = new ResVersion() { Version = remoteResVersion.Version, AssetBundleNames = new List <string>(), AssetBundleMD5s = new List <string>() }; remoteResVersion.AssetBundleNames.ForEach(name => UpdatedResVersion.AssetBundleNames.Add(name)); remoteResVersion.AssetBundleMD5s.ForEach(name => UpdatedResVersion.AssetBundleMD5s.Add(name)); //Delete DeleteUnusedBundle(remoteResVersion); //Get and return needDownload Names var needDownloadResVersion = GetNeedDownloadResVersion(remoteResVersion); onResult(needDownloadResVersion.AssetBundleNames); }