Last active
January 13, 2022 06:10
-
-
Save k4sima/e6a32dcf9cf472e133807ee728c7088b to your computer and use it in GitHub Desktop.
python-in-unity-test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using Python.Runtime; | |
using UnityEngine.UI; | |
public class pythontest : MonoBehaviour | |
{ | |
[SerializeField] private Text text; | |
void Start() | |
{ | |
Runtime.PythonDLL = Application.dataPath + "/StreamingAssets/python39/python39.dll"; | |
PythonEngine.Initialize(mode: ShutdownMode.Reload); | |
RunPython(); | |
} | |
public void OnApplicationQuit() | |
{ | |
if (PythonEngine.IsInitialized) | |
{ | |
PythonEngine.Shutdown(ShutdownMode.Reload); | |
} | |
} | |
private void RunPython() | |
{ | |
using (Py.GIL()) | |
{ | |
dynamic sysModule = Py.Import("sys"); | |
text.text = sysModule.version; //syatem info | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment