Run python script from unit to use its output (text file) in my game later

I'm trying to run a python script from unity (C # script) to use its output, which is a text file in my game later, the fact is that when I run C # script in unity nothing happens (Python script works fine on yourself). Can someone tell me what I am missing? Thank.

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;
        pythonInfo.FileName=@"C:\Users\HP\AppData\Local\Programs\Python\Python36-32\python.exe";
        pythonInfo.Arguments=@"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
source share
1 answer

, ( , Python ), Python IronPython, IronPython - Python CLR, 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 Engine, :

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/

+4

Source: https://habr.com/ru/post/1690924/


All Articles