// Use this for initialization
 void Start()
 {
     m_pyEnv = new PythonEnvironment();
     m_pyEnv.RunCommand(INITIALIZATION_CODE);
     m_pyOutput = string.Empty;
     m_pyCode = "for i in xrange(5):\n  g = UnityEngine.GameObject.CreatePrimitive(UnityEngine.PrimitiveType.Sphere)\n  g.name = 'PySphere' + str(i)\nprint 'Created 5 spheres'\n";
 }
示例#2
0
 // Use this for initialization
 void Start()
 {
     m_pyEnv = new PythonEnvironment();
     m_pyEnv.RunCommand(INITIALIZATION_CODE);
     m_pyEnv.ExposeVariable("Behavior", typeof(PyTest.PyBehaviorBase));
     m_pyOutput = string.Empty;
     m_pyCode   = "from UnityEngine import GameObject, Vector3, PrimitiveType\nfrom MyScripts import MyCustomClass\n\nfor i in xrange(5):\n  g = GameObject.CreatePrimitive(PrimitiveType.Sphere)\n  g.name = 'PySphere' + str(i)\n  g.transform.position = Vector3(i, i, 0)\n  g.AddComponent(MyCustomClass)\n  c = g.GetComponent(MyCustomClass)\n  c.someValue = i\nprint 'Created 5 spheres'\n";
 }
示例#3
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);
    }
示例#4
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());
            }
        }
    }
示例#5
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()));
     }
 }
示例#6
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);
 }