Good morning.
I have an xml where I keep the routes of some images.
my application creates a button for each route I have in the post xml, but I can not get the button to be created with the image in the routes, put an image of? which I think is the one with unity by default.
Would someone know how to help me and tell me where the fault is?
with this I read the xml (it works well)
public Datos ReadXmlTest() {
XmlSerializer serializer = new XmlSerializer(typeof(Datos));
StreamReader reader = new StreamReader(xmlPath);
Datos data = (Datos)serializer.Deserialize(reader);
reader.Close();
return data;
}
and then I have this one to generate the buttons for each element in the xml (it works fine) and then the part to put the image that works badly ..
void Awake() {
string path = "C:/datos.xml";
XmlManager xmlMng = new XmlManager(path);
data = xmlMng.ReadXmlTest();
foreach (var juego in data.Juegos) {
Button newButton = Instantiate(buttonPrefab);
newButton.transform.SetParent(layout);
newButton.GetComponent<AppButton>();
Sprite imageSprite = new Sprite();
Texture2D SpriteTexture = Texture(path);
imageSprite = Sprite.Create(SpriteTexture, new Rect(, , SpriteTexture.width, SpriteTexture.height), new Vector2(, ), 100.0f);
newButton.image.sprite = imageSprite;
}
}
public Texture2D Texture(string Path) {
Texture2D Texture2D;
byte[] FileData;
if (File.Exists(Path)) {
FileData = File.ReadAllBytes(Path);
Texture2D = new Texture2D(1, 1);
if (Texture2D.LoadImage(FileData))
return Texture2D;
}
return null;
}
my xml is:
<?xml version="1.0" encoding="utf-8"?>
<Datos>
<dato>
<prueba>
<ruta>C:/exe.exe</ruta>
<img>C:/Titulo.png</img>
</prueba>
<prueba>
<ruta>C:/exe1.exe</ruta>
<img>C:/titulo1.png</img>
</prueba>
<Datos>
<dato>