/// <summary> /// 请求下载动态资源 /// </summary> /// <param name="assetNameList"></param> public void RequestDynamicAssets(string[] assetNameList, Action <AssetUpdateInfo> DownloadProgressHandler, Action <AssetUpdateInfo> OnDownloadFinishCallback) { if (!this.IsUpdating) { List <BundleIndexItemInfo> dynamicBundleList = SQLiteBundlemapLoader.Instance.GetDynamicBundleIndexItemListByAssets(new List <string>(assetNameList)); this.OnUpdateFinishCallback = OnDownloadFinishCallback; if (dynamicBundleList.Count > 0) { this.UpdateProgressCallback = DownloadProgressHandler; SQLiteBundlemapLoader.Instance.RegisterDownloadBundleList(dynamicBundleList); AssetUpdateInfo downloadAssetsInfo = new AssetUpdateInfo(); for (int i = 0; i < dynamicBundleList.Count; ++i) { downloadAssetsInfo.AddUpdateBundleIndexItem(dynamicBundleList[i]); } StartDownloadAssets(downloadAssetsInfo); } else { CheckUpdateEnd(); } } }
public void StartDownloadAssets(AssetUpdateInfo assetUpdateInfo) { if (this.m_updateInfo == null) { this.m_updateInfo = assetUpdateInfo; } if (this.m_updateInfo != null && this.m_updateInfo.RemainDownloadAssetCount > 0) { this.m_updateInfo.StartDownloadTime = Time.time; ResourceModule.Instance.DownloadFilesFromServer(this.m_updateInfo.RemainDownloadFileList.ToArray(), OnDownloadedAsset, null, errorList => { if (errorList.Count > 0) { this.m_updateInfo.RetryErrorAssets(errorList); StartDownloadAssets(assetUpdateInfo); } else { CheckUpdateEnd(); } }, null, true); IsUpdating = true; } else { CheckUpdateEnd(); } }
private void CheckUpdateEnd() { if (this.m_updateInfo != null) { if (this.m_updateInfo.RemainDownloadAssetCount <= 0) { bundleMapLocal.ForceCommit(); OnUpdateFinishCallback?.Invoke(this.m_updateInfo); OnUpdateFinishCallback = null; UpdateProgressCallback = null; HasInitialized = true; this.m_updateInfo = null; IsUpdating = false; } else { UpdateProgressCallback?.Invoke(this.m_updateInfo); } } else { bundleMapLocal.ForceCommit(); OnUpdateFinishCallback?.Invoke(this.m_updateInfo); OnUpdateFinishCallback = null; UpdateProgressCallback = null; IsUpdating = false; HasInitialized = true; } }
/// <summary> /// 检查资源更新 /// </summary> /// <param name="UpdateAssetsCount"></param> internal void CheckUpdate(Action <int> UpdateAssetsCount) { SQLiteBundlemapLoader.Instance.CheckUpdate((diffResult) => { if (diffResult != null) { if (diffResult.DirtyBundleIndexList.Count > 0) { this.m_updateInfo = new AssetUpdateInfo(); for (int i = 0; i < diffResult.DirtyBundleIndexList.Count; ++i) { this.m_updateInfo.AddUpdateBundleIndexItem(diffResult.DirtyBundleIndexList[i]); } } //if (diffResult.ObsoleteBundleIndexList.Count > 0) // RemoveObsoleteBundle(diffResult.ObsoleteBundleIndexList); } UpdateAssetsCount(diffResult == null ? 0 : diffResult.DirtyBundleIndexList.Count); }); }