public void LoadThumbnail(string url, ImageComponentController imageComponentController) { Texture2D texture = LoadImageFromDisk(url); if (texture != null) { SetRawImageThumbnailObject(imageComponentController, texture); } }
public void RefreshEntries() { for (int i = 0; i < urls.Length; i++) { GameObject go = Instantiate(entryPrefab, parent); ImageComponentController imageComponentController = go.GetComponent <ImageComponentController>(); imageComponentController.RefreshImage(urls[i], downloader); } }
public void SetRawImageThumbnailObject(ImageComponentController imageComponentController, Texture2D texture) { if (imageComponentController.UsingRawImageComponent == true) { RawImage ri = imageComponentController.GetComponent <RawImage>(); ri.color = Color.white; ri.texture = texture; } else { Image image = imageComponentController.GetComponent <Image>(); image.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), imageComponentController.GetComponent <RectTransform>().pivot); } imageComponentController.ImageAssignedSuccessfully = true; }
protected IEnumerator UpdateThumbnail(string thumbnailURL, ImageComponentController imageComponentController, System.Action <Texture2D, string, ImageComponentController> onDownloadComplete) { UnityWebRequest www = UnityWebRequestTexture.GetTexture(thumbnailURL); yield return(www.SendWebRequest()); while (!www.isDone) { yield return(0); } if (www.error == null) { Texture2D texture = ((DownloadHandlerTexture)www.downloadHandler).texture; onDownloadComplete?.Invoke(texture, ExtractFileNameFromURL(thumbnailURL), imageComponentController); onDownloadComplete = null; } www.downloadHandler.Dispose(); www.Dispose(); }
public void StartThumbnailDownload(string thumbnailURL, ImageComponentController imageComponentController) { IEnumerator downloadObj = UpdateThumbnail(thumbnailURL, imageComponentController, OnDownloadComplete); StartCoroutine(downloadObj); }
public void OnDownloadComplete(Texture2D texture, string fileName, ImageComponentController imageComponentController) { SetRawImageThumbnailObject(imageComponentController, texture); SaveThumbnail(fileName, texture.EncodeToPNG()); }