2017-04-03 4 views
-1

私はいくつかの画像といくつかのexeのパスを保持するxmlを持っています。 xmlを読み込んで要素の数だけボタンを作成し、各ボタンに画像を割り当て、.exeを実行するボタンを与えるプログラムが必要ですC#Unityで.exeを実行する方法

私のプログラムはxmlを読み込んでボタンを作成します。私はイメージを持っているのボタンを必要と.exeが

私のクラス.EXE実行されたときに、ボタンを生成するために、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を読み込むからだと思う。

私はあなたがC#のから.exeを実行したい場合は、あなたが新しいProcessを作成し、.exeを起動することができ、それによってSystem.Diagnostics

を使用する必要があります

+0

[C#からの.exeの実行方法](http://stackoverflow.com/questions/12636991/how-to-run-exe-from-c-sharp) – PJvG

+0

の類似した質問がたくさんありますスタックオーバーフロー:http://stackoverflow.com/search?q=c%23+run+exe – PJvG

答えて

3

私はスペイン語jejejeよ、あなたは私を理解してほしいです

この例では、MSDNドキュメント

using System; 
using System.Diagnostics; 
using System.ComponentModel; 

namespace MyProcessSample 
{ 
    class MyProcess 
    { 
     public static void Main() 
     { 
      Process myProcess = new Process(); 

      try 
      { 
       myProcess.StartInfo.UseShellExecute = false; 
       // You can start any process, HelloWorld is a do-nothing example. 
       myProcess.StartInfo.FileName = "C:\\HelloWorld.exe"; 
       myProcess.StartInfo.CreateNoWindow = true; 
       myProcess.Start(); 
       // This code assumes the process you are starting will terminate itself. 
       // Given that is is started without a window so you cannot terminate it 
       // on the desktop, it must terminate itself or you can do it programmatically 
       // from this application using the Kill method. 
      } 
      catch (Exception e) 
      { 
       Console.WriteLine(e.Message); 
      } 
     } 
    } 
} 

01からのものです

関連する問題