Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using TMPro;
- using UnityEngine;
- using UnityEngine.Networking;
- using UnityEngine.UI;
- public class DownloadMultipleImageFromGoogleDrive : MonoBehaviour
- {
- [SerializeField] private TMP_Text imageID;
- [SerializeField] private TMP_Text imageName;
- [SerializeField] private RawImage rawImage;
- [SerializeField] private PhotoList photoList;
- private string JsonURL = "https://drive.google.com/uc?export=download&id=1WrQGpdb53_UoUxeyWCOHE-XB8ujWLS7R";
- void Start()
- {
- StartCoroutine(GetJsonFile());
- }
- IEnumerator GetJsonFile()
- {
- UnityWebRequest webRequest = UnityWebRequest.Get(JsonURL);
- yield return webRequest.SendWebRequest();
- if (webRequest.result != UnityWebRequest.Result.Success)
- {
- Debug.LogError("Json File Not Download : "+ webRequest.error);
- }
- else
- {
- photoList = JsonUtility.FromJson<PhotoList>(webRequest.downloadHandler.text);
- foreach (Photo photo in photoList.Photos)
- {
- imageID.text = photo.ImageID;
- imageName.text = photo.ImageName;
- StartCoroutine(GetImage(photo.ImageURL));
- yield return new WaitForSeconds(5);
- }
- }
- }
- IEnumerator GetImage(string imageURL)
- {
- UnityWebRequest webRequestTexture = UnityWebRequestTexture.GetTexture(imageURL);
- yield return webRequestTexture.SendWebRequest();
- if (webRequestTexture.result != UnityWebRequest.Result.Success)
- {
- Debug.LogError("Image Not Download : "+webRequestTexture.error);
- }
- else
- {
- rawImage.texture = ((DownloadHandlerTexture) webRequestTexture.downloadHandler).texture;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement