Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        for (int i = 0; i < 1; i++)
        {
            m_pyEnv.ExposeVariable("input", JsonUtility.ToJson(input));

            PythonEnvironment.CommandResult r = m_pyEnv.RunCommand(m_pyCode);



            if (r.exception != null)
            {
                Debug.Log(r.exception.ToString());
            }
        }
    }
Beispiel #2
0
 internal void ExecuteCode(string command)
 {
     PythonEnvironment.CommandResult result = m_pythonEnvironment.RunCommand(command.TrimEnd());
     if (!string.IsNullOrEmpty(result.output))
     {
         m_historyItems.Add(new KeyValuePair <HistoryItemType, string>(HistoryItemType.OUTPUT, result.output));
     }
     if (!string.IsNullOrEmpty(result.returnValueStr))
     {
         m_historyItems.Add(new KeyValuePair <HistoryItemType, string>(HistoryItemType.RETURN_VALUE, result.returnValueStr));
     }
     if (result.exception != null)
     {
         m_historyItems.Add(new KeyValuePair <HistoryItemType, string>(HistoryItemType.ERROR, result.exception.ToString()));
     }
 }
Beispiel #3
0
 void OnGUI()
 {
     m_pyCode = GUI.TextArea(new Rect(50, 50, 600, 200), m_pyCode);
     if (GUI.Button(new Rect(50, 270, 80, 40), "Run"))
     {
         m_pyOutput = string.Empty;
         PythonEnvironment.CommandResult result = m_pyEnv.RunCommand(m_pyCode);
         if (!string.IsNullOrEmpty(result.output))
         {
             m_pyOutput += "Python output : " + result.output + System.Environment.NewLine;
         }
         if (result.exception != null)
         {
             m_pyOutput += "Python exception : " + result.exception.Message;
         }
     }
     GUI.TextArea(new Rect(50, 330, 600, 300), m_pyOutput);
 }
Beispiel #4
0
    // Use this for initialization
    void Start()
    {
        spheres = new List <GameObject>();

        m_pyEnv = new PythonEnvironment();
        m_pyEnv.RunCommand(INITIALIZATION_CODE);
        m_pyEnv.RunCommand("from UnityEngine import GameObject, Vector3, PrimitiveType, Mathf");

        PythonEnvironment.CommandResult r = m_pyEnv.RunCommand("from json import decoder");
        if (r.exception != null)
        {
            Debug.Log(r.exception.ToString());
        }

        m_pyEnv.ExposeVariable("Behavior", typeof(PyTest.PyBehaviorBase));

        spheres.Add(GameObject.CreatePrimitive(PrimitiveType.Sphere));

        m_pyEnv.ExposeVariable("timer", timer);

        m_pyCode = System.IO.File.ReadAllText("Test.py");

        input = new PythonInput();

        input.index = new int[20];
        for (int i = 0; i < input.index.Length; i++)
        {
            input.index[i] = i;
        }

        input.timer = new float[20];
        for (int i = 0; i < input.index.Length; i++)
        {
            input.timer[i] = i * 1f;
        }

        string json = JsonUtility.ToJson(input);
    }