我正在尝试将IronPython嵌入Unity 3D项目中,但遇到了一些似乎无法弄清的错误。
我将以下脚本附加到Unity中的GameObject。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using IronPython;
using IronPython.Modules;
using System.Text;
public class IronPythonWrapper : MonoBehaviour {
void Start() {
ScriptTest();
}
public static void ScriptTest() {
// create the engine
var engine = IronPython.Hosting.Python.CreateEngine();
// and the scope (i.e. the Python namespace)
var scope = engine.CreateScope();
// execute the Python script
engine.ExecuteFile("Assets/Scripts/ipscript.py");
// grab the variable from the Python scope
string commands = scope.GetVariable<string>("commands");
Debug.Log(commands);
}
}
目标是让上面实例化的IronPython引擎执行以下名为的简单Python脚本ipscript.py
。
commands = "Script executed."
当我进入播放模式(在Unity中)时,出现以下错误。
MissingMemberException: 'ScopeStorage' object has no attribute 'commands'
有谁知道我应该调查什么以解决此问题?也许我需要实现一些错误捕获,以便我可以看到IronPython在执行Python脚本时生成的任何异常?
您的python执行未正确传递范围。commands
因此,您的变量是在执行python文件后被丢弃的瞬时作用域上创建的,而显式创建的作用域不知道是什么commands
。
该代码段应显示为
engine.ExecuteFile("Assets/Scripts/ipscript.py", scope);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句