Hello, I am creating a dynamic widget based on XML. Basically you open the widget of an author based on XML. In that string you have a tag which instantiates a prefab to display the gallery, which items on the XML are the type of the tag opened previously.
Up to this point everything works, but I have the following problem: the images of the gallery have to be downloaded from the internet, the path to each image is on the XML. But I can’t manage to update the image when it downloads, this is what I’ve got:
public class IItems
{
public string itemID { get; private set; }
public string itemType { get; private set; }
public string title { get; private set; }
public string imagePath { get; private set; }
public Texture2D texture { get; private set; }
public IItems(XmlNode node)
{
itemID = node.Attributes["ID"].Value;
itemType = node.Attributes["Type"].Value;
title = node["ObraTitle"].InnerText;
imagePath = node["ImagePath"].InnerText;
}
public void UpdateInventoryUI(GameObject inventoryUI)
{
UITestScript.Instance.Run(GetImage(imagePath));
Transform inventoryUITransform = inventoryUI.transform;
Image itemBGPanel;
Text itemTitleText;
RawImage itemRawImage;
itemBGPanel = inventoryUITransform.GetComponent<Image>();
Transform itemBGPanelTransform = itemBGPanel.GetComponent<Transform>();
itemTitleText = itemBGPanelTransform.Find("TitleText").GetComponent<Text>();
itemTitleText.text = title;
itemRawImage = itemBGPanelTransform.Find("ItemRawImage").GetComponent<RawImage>();
itemRawImage.texture = texture;
//I NEED THIS TO BE THE IMAGE DOWNLOADED ON THE IENUMERATOR
}
IEnumerator GetImage(string path)
{
UnityWebRequest wwwImage = UnityWebRequestTexture.GetTexture(path);
var operation = wwwImage.SendWebRequest();
while (!wwwImage.isDone) //este codigo se va a loopear hasta que la textura se termine de descargar y va a traer la info de qu eesta haciendo unitywebrequest
{
var progress = operation.progress;
UnityEngine.Debug.Log(progress);
yield return null;//salto al otro frame para que vuelva a empezar si el www aun no es Done
}
yield return wwwImage;
Texture2D image = ((DownloadHandlerTexture)wwwImage.downloadHandler).texture;
if (wwwImage.isDone)
{
Rect rect = new Rect(0, 0, image.width, image.height);
texture = image;
}
}
}
so I don’t exactly know how to update the raw image to the instantiated object thank you!