/// <summary> /// Returns the array of ContentDownloadItem for given ContentInfo. /// Creates them if they were not created before. /// </summary> /// <returns>The content download items.</returns> /// <param name="contentInfo">Content info array.</param> public ContentDownloadItem[] GetContentDownloadItems(ContentInfo[] contentInfo) { ContentDownloadItem[] contentDownloadItems = new ContentDownloadItem[contentInfo.Length]; for (int i = 0; i < contentInfo.Length; i++) { contentDownloadItems[i] = GetContentDownloadItem(contentInfo[i]); } return(contentDownloadItems); }
internal void RequestRefresh(ContentDownloadItem contentDownloadItem) { if (contentDownloadItem.State == ContentDownloadState.Complete || contentDownloadItem.State == ContentDownloadState.Unknown) { StartCoroutine(RefreshContent(contentDownloadItem)); } else { contentDownloadItem.NotifyRefreshStateChange(); } }
private IEnumerator RefreshContent(ContentDownloadItem contentDownloadItem) { string resourceAssetBundleName = contentDownloadItem.ContentInfo.ResourceAssetBundleName; string sceneAssetBundleName = contentDownloadItem.ContentInfo.SceneAssetBundleName; if (contentDownloadItem.RefreshYieldInstruction != null) { contentDownloadItem.RefreshYieldInstruction.Dispose(); contentDownloadItem.RefreshYieldInstruction = null; } using (AbstractDownloaderYieldInstruction refreshYieldInstruction = CreateRefreshYieldInstruction(resourceAssetBundleName, sceneAssetBundleName)) { contentDownloadItem.RefreshYieldInstruction = refreshYieldInstruction; contentDownloadItem.NotifyDownloadStateChange(ContentDownloadState.Refreshing); yield return(refreshYieldInstruction); if (!refreshYieldInstruction.IsDisposed) { contentDownloadItem.State = refreshYieldInstruction.DownloadState; contentDownloadItem.Error = ContentDownloadError.None; if (AssetBundleOptions.UseAssetBundlesInEditor) { if (contentDownloadItem.State == ContentDownloadState.Complete) { //Resource is already on disk, we retain it if (contentDownloadItem.ResourceAssetBundle == null) { contentDownloadItem.ResourceAssetBundle = DownloadAssetBundleReference.FindOrCreateReference(resourceAssetBundleName); contentDownloadItem.ResourceAssetBundle.Retain(); } if (contentDownloadItem.SceneAssetBundle == null) { contentDownloadItem.SceneAssetBundle = DownloadAssetBundleReference.FindOrCreateReference(sceneAssetBundleName); contentDownloadItem.SceneAssetBundle.Retain(); } } else if (contentDownloadItem.State == ContentDownloadState.Unknown) { //Resource is not on disk any more, we release it contentDownloadItem.ReleaseAssetBundles(); } } refreshYieldInstruction.Dispose(); contentDownloadItem.RefreshYieldInstruction = null; contentDownloadItem.NotifyRefreshStateChange(); } } }
/// <summary> /// Returns the ContentDownloadItem for given ContentInfo. /// Creates it if none was created before. /// </summary> /// <returns>The content download item.</returns> /// <param name="contentInfo">Content info.</param> public ContentDownloadItem GetContentDownloadItem(ContentInfo contentInfo) { if (!this.DownloadItemsByContentInfo.ContainsKey(contentInfo)) { ContentDownloadItem item = new ContentDownloadItem(); item.ContentInfo = contentInfo; item.ContentDownloader = this; this.DownloadItemsByContentInfo.Add(contentInfo, item); } return(this.DownloadItemsByContentInfo[contentInfo]); }
internal void CancelRefresh(ContentDownloadItem contentDownloadItem) { if (contentDownloadItem.RefreshYieldInstruction != null) { contentDownloadItem.RefreshYieldInstruction.Dispose(); contentDownloadItem.RefreshYieldInstruction = null; } if (contentDownloadItem.State == ContentDownloadState.Refreshing) { contentDownloadItem.State = ContentDownloadState.Unknown; } }
internal void CancelDownload(ContentDownloadItem contentDownloadItem, bool forceReset = false) { if (contentDownloadItem.State != ContentDownloadState.Complete || forceReset) { if (contentDownloadItem.DownloadYieldInstruction != null) { contentDownloadItem.DownloadYieldInstruction.Dispose(); contentDownloadItem.DownloadYieldInstruction = null; } DownloadQueue.Remove(contentDownloadItem); contentDownloadItem.NotifyDownloadStateChange(ContentDownloadState.Unknown); if (this.OnDownloaderDownloadCancel != null) { this.OnDownloaderDownloadCancel(contentDownloadItem); } } }
internal void RequestDownload(ContentDownloadItem contentDownloadItem) { if (contentDownloadItem.State == ContentDownloadState.Unknown) { if (!IsInternetAvailable()) { if (DownloadViaWiFiOnly) { contentDownloadItem.NotifyDownloadStateChange(ContentDownloadState.Error, ContentDownloadError.NoWifi); } else { contentDownloadItem.NotifyDownloadStateChange(ContentDownloadState.Error, ContentDownloadError.NoInternet); } } else { this.DownloadQueue.AddLast(contentDownloadItem); contentDownloadItem.NotifyDownloadStateChange(ContentDownloadState.Queued); } } }
private IEnumerator DownloadContent(ContentDownloadItem contentDownloadItem) { if (this.OnDownloaderDownloadStart != null) { this.OnDownloaderDownloadStart(contentDownloadItem); } string resourceAssetBundleName = contentDownloadItem.ContentInfo.ResourceAssetBundleName; string sceneAssetBundleName = contentDownloadItem.ContentInfo.SceneAssetBundleName; if (contentDownloadItem.DownloadYieldInstruction != null) { contentDownloadItem.DownloadYieldInstruction.Dispose(); contentDownloadItem.DownloadYieldInstruction = null; } using (AbstractDownloaderYieldInstruction downloadYieldInstruction = CreateDownloadYieldInstruction(resourceAssetBundleName, sceneAssetBundleName)) { contentDownloadItem.DownloadYieldInstruction = downloadYieldInstruction; contentDownloadItem.NotifyDownloadStateChange(ContentDownloadState.Downloading); yield return(downloadYieldInstruction); if (!downloadYieldInstruction.IsDisposed) { ContentDownloadError error = downloadYieldInstruction.DownloadError; string errorMessage = downloadYieldInstruction.DownloadErrorMessage; if (error == ContentDownloadError.None && downloadYieldInstruction.ResourceAssetBundle != null && downloadYieldInstruction.SceneAssetBundle != null) { //Download Complete, we retain the resources directly on this contentDownloadItem contentDownloadItem.ReleaseAssetBundles(); contentDownloadItem.ResourceAssetBundle = downloadYieldInstruction.ResourceAssetBundle; contentDownloadItem.ResourceAssetBundle.Retain(); contentDownloadItem.SceneAssetBundle = downloadYieldInstruction.SceneAssetBundle; contentDownloadItem.SceneAssetBundle.Retain(); } downloadYieldInstruction.Dispose(); contentDownloadItem.DownloadYieldInstruction = null; if (error != ContentDownloadError.None) { m_DownloadError = error; contentDownloadItem.NotifyDownloadStateChange(ContentDownloadState.Error, error); if (this.OnDownloaderDownloadError != null) { this.OnDownloaderDownloadError(m_DownloadError, errorMessage, contentDownloadItem); } if (this.OnDownloaderDownloadFinish != null) { this.OnDownloaderDownloadFinish(contentDownloadItem, false); } } else { contentDownloadItem.NotifyDownloadStateChange(ContentDownloadState.Complete); if (this.OnDownloaderDownloadFinish != null) { this.OnDownloaderDownloadFinish(contentDownloadItem, true); } } } else { if (this.OnDownloaderDownloadFinish != null) { this.OnDownloaderDownloadFinish(contentDownloadItem, false); } } } }