/** * Return a texture from a url that points to an image resource * * This method does not block but queues a request to fetch the image and return null. * When the image has been fetched this method will return the image texture downloaded. */ public static CachedAssetStoreImage TextureFromUrl(string url, string label, int textureSize, GUIStyle labelStyle, GUIStyle iconStyle, bool onlyCached) { if (string.IsNullOrEmpty(url)) { return(Instance.m_DummyItem); } CachedAssetStoreImage cached; bool newentry = true; if (CachedAssetStoreImages.TryGetValue(url, out cached)) { cached.lastUsed = EditorApplication.timeSinceStartup; // Refetch the image if the size has changed and is not in the progress of being fetched bool refetchInitiated = cached.requestedWidth == textureSize; bool correctSize = cached.image != null && cached.image.width == textureSize; bool cacheRequestAborted = cached.requestedWidth == -1; if ((correctSize || refetchInitiated || onlyCached) && !cacheRequestAborted) { Instance.CacheHit++; // Use cached image (that may be null) if we're in progress of fetching the image // or if we have rendered the images correctly //return cached; bool fetchingImage = cached.client != null; bool labelDrawn = cached.label == null; bool valid = fetchingImage || labelDrawn; bool convPerTickExceeded = Instance.m_ConvertedThisTick > kMaxConvertionsPerTick; s_NeedsRepaint = s_NeedsRepaint || convPerTickExceeded; return((valid || convPerTickExceeded) ? cached : RenderEntry(cached, labelStyle, iconStyle)); } //Debug.Log(string.Format("Found {0} {1} {2} {3}", correctSize, refetchInitiated, onlyCached, cacheRequestAborted)); newentry = false; if (Downloading >= kMaxConcurrentDownloads) { return(cached.image == null ? Instance.m_DummyItem : cached); } } else { if (onlyCached || Downloading >= kMaxConcurrentDownloads) { return(Instance.m_DummyItem); } cached = new CachedAssetStoreImage(); cached.image = null; cached.lastUsed = EditorApplication.timeSinceStartup; //Debug.Log("url is " + textureSize.ToString() + " " + url); } // Only set fetch time when there is not image in order to use it for // fading in the image when it becomes available if (cached.image == null) { cached.lastFetched = EditorApplication.timeSinceStartup; } cached.requestedWidth = textureSize; cached.label = label; AsyncHTTPClient client = null; client = SetupTextureDownload(cached, url, "previewSize-" + textureSize); ExpireCacheEntries(); if (newentry) { CachedAssetStoreImages.Add(url, cached); } client.Begin(); Instance.Requested++; return(cached); }