-1
我有一個xml,我保留了一些圖像和一些exe的路徑。 我需要我的程序來讀取XML並創建儘可能多的按鈕,因爲有元素,分配每個按鈕的圖像,並給它的按鈕來運行.exe我的程序讀取XML並創建按鈕。我需要的按鈕,有圖像,當.exe文件運行.exe文件我怎樣才能在C#中運行.exe Unity
我的類讀取XML
using System.IO;
using System.Xml.Serialization;
public class XmlManager {
private string xmlPath;
public XmlManager(string xmlPath) {
this.xmlPath = xmlPath;
}
public Datos ReadXmlTest() {
XmlSerializer serializer = new XmlSerializer(typeof(Datos));
StreamReader reader = new StreamReader(xmlPath);
Datos data = (Datos)serializer.Deserialize(reader);
reader.Close();
return data;
}
}
我的類來生成按鈕,並把德圖像按鈕
using System.IO;
using UnityEngine;
using UnityEngine.UI;
public class AppLogic : MonoBehaviour {
[SerializeField]
private Transform layout;
[SerializeField]
private Button buttonPrefab;
private Datos data;
void Awake() {
string path = "C:/Users/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(0, 0, SpriteTexture.width, SpriteTexture.height), new Vector2(0, 0), 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;
}
}
我的XML文件
<?xml version="1.0" encoding="utf-8"?>
<Datos>
<dato>
<play>
<ruta>D:/exe.exe</ruta>
<img>C:/png.png</img>
</play>
<play>
<ruta>D:/exe1.exe</ruta>
<img>C:/png1.png</img>
</play>
</dato>
</Datos>
我的程序時創建的按鈕放在統一的默認圖像。我認爲這是因爲它讀取所有的XML而不僅僅是一個圖像。
我希望你能理解我,我西班牙人jejeje
可能的重複[如何從C#運行.exe](http://stackoverflow.com/questions/12636991/how-to-run-exe-from-c-sharp) – PJvG
有許多類似的問題堆棧溢出:http://stackoverflow.com/search?q=c%23+run+exe – PJvG