-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPythonExample.cs
More file actions
53 lines (43 loc) · 1.49 KB
/
PythonExample.cs
File metadata and controls
53 lines (43 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System.Collections;
using System.Collections.Generic;
using IronPython.Hosting;
using UnityEngine;
using System.IO;
using UnityEngine.UI;
public class PythonExample : MonoBehaviour
{
[SerializeField]
private Text greeting, randomNumber;
// Use this for initialization
void Start ()
{
var engine = Python.CreateEngine ();
ICollection<string> searchPaths = engine.GetSearchPaths ();
#if UNITY_STANDALONE_WIN
//Path to the folder of test.py
searchPaths.Add (Application.dataPath);
//Path to the Python standard library
searchPaths.Add (Application.dataPath + @"\StreamingAssets" + @"\Lib\");
engine.SetSearchPaths (searchPaths);
dynamic py = engine.ExecuteFile (Application.dataPath + @"\StreamingAssets" + @"\Python\test.py");
dynamic test = py.Test ("Codemaker");
greeting.text = "Greeting: " + test.display ();
randomNumber.text = "Random Number: " + test.random_number (1, 5);
#endif
#if UNITY_ANDROID
//Path to the folder of test.py
searchPaths.Add (Application.persistentDataPath);
//Path to the Python standard library
searchPaths.Add (Application.persistentDataPath + @"\Lib\");
engine.SetSearchPaths (searchPaths);
dynamic py = engine.ExecuteFile (Application.persistentDataPath + @"\Python\test.py");
dynamic test = py.Test ("Codemaker");
greeting.text = "Greeting: " + test.display ();
randomNumber.text = "Random Number: " + test.random_number (1, 5);
#endif
}
// Update is called once per frame
void Update ()
{
}
}