Commit ce2cf9fd authored by joni's avatar joni
Browse files

added error handling, renamed SetPath to Load.

parent 8568ab2f
......@@ -89,8 +89,9 @@ public class QuantumDemoManager : MonoBehaviour
// Start is called before the first frame update
void Start()
{
// InitEnv();
{
// InitEnv();
PythonLoader.Load();
FinalScoreObject.SetActive(false);
StartTextObject.SetActive(true);
m_left.enabled = false;
......
......@@ -7,7 +7,7 @@ public class ExampleStirap : MonoBehaviour
{
UnityEngine.Random.InitState(9989);
PythonLoader.SetPath("Assets\\Plugins\\QuantumWheel\\.Python");
PythonLoader.Load();
Debug.Log("path: " + System.Runtime.InteropServices.Marshal.PtrToStringUni(Python.Runtime.Runtime.Py_GetPath()));
using (Python.Runtime.Py.GIL())
{
......
......@@ -51,10 +51,38 @@ public class PythonManager/* : MonoBehaviour*/
}
public class PythonLoadException : System.Exception
{
public PythonLoadException(string msg) : base(msg)
{
}
}
public class PythonLoader
{
public static void SetPath(string path)
public static void Load()
{
#if UNITY_EDITOR
Load("Assets\\Plugins\\QuantumWheel\\.Python");
#else
Load("Python");
#endif
}
private static void checkAndThrow(string path)
{
if (!File.Exists(path + "\\orig-prefix.txt"))
{
throw new PythonLoadException("Could not find python at " + path);
}
}
public static void Load(string path)
{
checkAndThrow(path);
Runtime.Py_SetPath(System.Runtime.InteropServices.Marshal.StringToHGlobalUni(new DirectoryInfo(path).FullName));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment