public void QueryImageDataFromCacheForURL(string url, DGSWebImageOptions options, Action <byte[]> callback) { if ((options & DGSWebImageOptions.MemoryCache) != 0 && ImageDataExistsInMemory(url)) { var data = LoadImageDataFromMemory(url); if (data != null) { callback?.Invoke(data); return; } } if ((options & DGSWebImageOptions.DiskCache) != 0 && ImageDataExistsInDisk(url)) { var data = LoadImageDataFromDisk(url); if (data != null) { callback?.Invoke(data); return; } } callback?.Invoke(null); }
public void RemoveImageDataFromCache(string url, DGSWebImageOptions options) { if ((options & DGSWebImageOptions.MemoryCache) != 0) { RemoveImageDataFromMemory(url); } if ((options & DGSWebImageOptions.DiskCache) != 0) { RemoveImageDataFromDisk(url); } }
private void InternalSetImageWithURL(string url, Texture2D placeholder, DGSWebImageOptions options, Action <float> progressCallback, Action <Texture2D> completionCallback) { if (placeholder != null) { if (completionCallback != null) { completionCallback(placeholder); } } if (string.IsNullOrEmpty(url)) { Debug.LogWarning("Image url isn't set"); return; } if ((options & DGSWebImageOptions.ShowLoadingIndicator) != 0 && loadingIndicator) { loadingIndicator.SetActive(true); } DGSWebImageManager.Instance.LoadImageWithURL(url, options, progressCallback, (error, texture) => { if ((options & DGSWebImageOptions.ShowLoadingIndicator) != 0 && loadingIndicator) { loadingIndicator.SetActive(false); } if (error != null) { Debug.LogWarning(error.description); if (OnLoadingError != null) { OnLoadingError(error); } return; } if (OnImageSizeReady != null) { OnImageSizeReady(new Vector2(texture.width, texture.height)); } if (completionCallback != null) { completionCallback(texture); } }); }
public void CacheImageDataForURL(string url, byte[] data, DGSWebImageOptions options) { if ((options & DGSWebImageOptions.MemoryCache) != 0) { ThreadPool.QueueUserWorkItem((state) => { StoreImageDataInMemory(url, data); }); } if ((options & DGSWebImageOptions.DiskCache) != 0) { ThreadPool.QueueUserWorkItem((state) => { StoreImageDataInDisk(url, data); }); } }
public void LoadImageWithURL(string url, DGSWebImageOptions options, Action <float> progressCallback, Action <DGSWebImageDownloaderError, Texture2D> completionCallback) { if (_failedURLs.Contains(url)) { if (completionCallback != null) { completionCallback(new DGSWebImageDownloaderError("Unable to convert downloaded data into texture"), null); } return; } DGSImageCache.Instance.QueryImageDataFromCacheForURL(url, options, (cachedData) => { if (cachedData != null) { var texture = TextureFromData(cachedData); if (texture != null) { if (completionCallback != null) { completionCallback(null, texture); } return; } DGSImageCache.Instance.RemoveImageDataFromCache(url, options); } StartCoroutine(DGSWebImageDownloader.Instance.DownloadImageWitURL(url, progressCallback, (error, downloadedData) => { if (error != null) { if (error.type == DGSWebImageDownloaderError.ErrorType.InvalidURL || error.type == DGSWebImageDownloaderError.ErrorType.NotFound || error.type == DGSWebImageDownloaderError.ErrorType.FailedURL) { _failedURLs.Add(url); } if (completionCallback != null) { completionCallback(error, null); } return; } if (downloadedData != null) { if (completionCallback != null) { completionCallback(null, TextureFromData(downloadedData)); } DGSImageCache.Instance.CacheImageDataForURL(url, downloadedData, options); } })); }); }
/// <summary> /// Loads a web image. /// </summary> /// <param name="url">URL of the image to be loaded.</param> /// <param name="placeholder">Texture to be used during image loading.</param> /// <param name="options">Custom options for the DGSWebImage.</param> /// <param name="progressCallback">Called periodically to indicate the download progress.</param> /// <param name="completionCallback">Called when the image is loaded.</param> public void SetImageWithURL(string url, Texture2D placeholder, DGSWebImageOptions options, Action <float> progressCallback, Action <Texture2D> completionCallback) { InternalSetImageWithURL(url, placeholder, options, progressCallback, completionCallback); }
/// <summary> /// Sets the target component with a web image. /// </summary> /// <param name="url">URL of the image to be loaded.</param> /// <param name="placeholder">Texture to be used during image loading.</param> /// <param name="options">Custom options for the DGSWebImage.</param> public void SetImageWithURL(string url, Texture2D placeholder, DGSWebImageOptions options) { InternalSetImageWithURL(url, placeholder, options, null, SetTexture); }