コード例 #1
0
        public void UpdateAssetBundle(UpdateInfo updateInfo, Dictionary <string, string> headers,
                                      IEnumerable <AssetBundleInfo> assetBundleifInfos,
                                      VersionInfo persistentInfos, string version, GameFrameworkAction <DownloadProgressInfo, string> progressHandle = null,
                                      GameFrameworkAction <AssetBundleInfo> anyCompleteHandle = null, GameFrameworkAction allCompleteHandle = null,
                                      GameFrameworkAction <string> errorHandle = null)
        {
            DownloadManager.AllCompleteHandle = () =>
            {
                persistentInfos.SetVersion(version);

                _updateVersionInfoFile(persistentInfos);
                allCompleteHandle?.Invoke();
            };
            List <DownloadUnitInfo> downloadUnitInfos = new List <DownloadUnitInfo>();

            foreach (var assetBundleInfo in assetBundleifInfos)
            {
                var downloadTools = new UnityWebRequestDownload(_coroutine);
                if (headers != null)
                {
                    var unityWeb = (UnityWebRequest)downloadTools.DownlodTool;

                    foreach (var pair in headers)
                    {
                        unityWeb.SetRequestHeader(pair.Key, pair.Value);
                    }
                }
                downloadUnitInfos.Add(new DownloadUnitInfo()
                {
                    CompleteHandle = x =>
                    {
                        persistentInfos.AddOrUpdateAssetBundleInfo(assetBundleInfo);

                        _updateVersionInfoFile(persistentInfos);

                        anyCompleteHandle?.Invoke(assetBundleInfo);
                        //解压
                        Utility.ZipUtil.UnzipZip(x, Application.persistentDataPath);
                        GameFramework.Utility.FileUtil.DeleteFile(x);
                    },
                    ErrorHandle            = errorHandle.Invoke,
                    DownloadProgressHandle = progressHandle.Invoke,
                    FileName           = assetBundleInfo.PackName.Replace("dat", "zip"),
                    SavePath           = Path.Combine(Application.persistentDataPath, assetBundleInfo.PackPath),
                    Url                = updateInfo.AssetBundleUrl + "/" + assetBundleInfo.PackFullName.Replace("dat", "zip"),
                    IsFindCacheLibrary = false, //ab包更新不找缓存
                    DownloadUtil       = downloadTools,
                    Headers            = headers
                });
            }

            DownloadManager.AddRangeDownload(downloadUnitInfos);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="outputPackPath">xx.dat 或 xx.xx.dat的父目录</param>
        /// <param name="abData"></param>
        void _addOrUpdateAsssetBundle(string outputPackPath, AssetBundleData abData)
        {
            var packName = GetAssetBundleFullName(abData.Name, abData.Variant);

            packName = packName.Split('\\', '/').Last();
            packName = GameFramework.Utility.Path.GetResourceNameWithSuffix(packName);
            var dir = Path.GetDirectoryName(abData.Name);

            var info = new AssetBundleInfo()
            {
                PackName = packName,
                PackPath = dir,
                Optional = abData.Optional,
                GroupTag = abData.GroupTag
            };

            info.MD5 = GameFramework.Utility.MD5Util.GetFileMd5(Path.Combine(outputPackPath, info.PackFullName));

            _version.AddOrUpdateAssetBundleInfo(info);
        }