2017-12-17 11 views
4

私のゲームのテキストファイルである出力を使用するために、unity(C#スクリプト)からPythonスクリプトを実行しようとしています私がC#スクリプトを1つに実行すると、何も起こりません(Pythonスクリプトはうまく動作します)。私が何が欠けているか教えてもらえますか?おかげさまで 私のゲームでその出力(テキストファイル)を後で使用するために、unityからPythonスクリプトを実行します。

using UnityEngine; 
using System.Collections; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Text; 
using System.IO; 
using UnityEngine.UI; 
using System.Text.RegularExpressions; 
using System.Diagnostics; 

using System.Runtime.InteropServices; 
public class PyCx : MonoBehaviour { 
    public Text Message; 
    public GameObject OpenPanel1 = null; 
    // Use this for initialization 
    void Start() { 
     python(); 
     read(); 
     ShowMessage(); 
    } 
    public void python(){ 
     ProcessStartInfo pythonInfo = new ProcessStartInfo(); 
     Process python; 
     [email protected]"C:\Users\HP\AppData\Local\Programs\Python\Python36-32\python.exe"; 
     [email protected]"C:\Users\HP\Documents\projet1.pyw"; 
     pythonInfo.CreateNoWindow = false; 
     pythonInfo.UseShellExecute = false; 
     python = Process.Start (pythonInfo); 
     python.WaitForExit(); 
     python.Close(); 
    } 
    public void read(){ 
     using (var reader = new StreamReader ("C://Users//HP//Documents//result.txt")) { 
      string line = reader.ReadToEnd(); 
      Message.text = (line); 
     } 
    } 
    public void ShowMessage(){ 
     OpenPanel1.SetActive (true); 
     Message.IsActive(); 
    } 
    // Update is called once per frame 
    void Update() { 

    } 
} 

答えて

4

の代わりにあなたの制御開発環境外で信頼できないプロセスを使用して、(ユーザーがさえPythonがインストールされているバージョンをしているかどうかがわからない)あなたが使用してコード内で直接のPythonを実行しようとすることができIronPython、IronPythonはCLR用のPythonインタプリタですので、Pythonをインストールしてスクリプトを実行する必要はありません。あなたはその後、あなたのリソースフォルダ内のすべての必要なアセンブリをコピーしhttp://ironpython.net/download/

からコンパイルされたバイナリをダウンロードする必要があり、それを使用するには

  • IronPython.dll
  • IronPython.Modules.dll
  • Microsoft.Scripting.Core.dll
  • Microsoft.Scripting.dll
  • Microsoft.Scripting.Debugging.dll
  • Microsoft.Scripting.ExtensionAttribute.dll
  • Microsoft.Dynamic.dll

次に、あなたは、Pythonエンジンにアクセスする必要があります次のように、あなたはそれを初期化することができます。

PythonEngine engine = new PythonEngine(); 
engine.LoadAssembly(Assembly.GetAssembly(typeof(GameObject)));   
engine.ExecuteFile("Project1.py"); 

あなたはここで詳細情報を見ることができます:http://ironpython.net/documentation/

参照

http://shrigsoc.blogspot.com.es/2016/07/ironpython-and-unity.html https://forum.unity.com/threads/ironpython-in-unity-a-good-idea.225544/

+0

私はPythonEngineはMonoDevelopの中で認識され得ることはできません! – Ran

関連する問題