在Unity 5.3.1f中使用C#动态类型
我已经为我的游戏编写了需要运行python代码函数的代码。我正在为我的项目使用Ironpython。 但是,当我尝试使用C#动态类型调用下面代码中的函数时,它会编译,但我从内部得到以下错误: “Assets/Scripts/WordSearchAlgorithm.cs(37,29):错误CS1502:在Unity 5.3.1f中使用C#动态类型,c#,unity3d,ironpython,dynamic-typing,C#,Unity3d,Ironpython,Dynamic Typing,我已经为我的游戏编写了需要运行python代码函数的代码。我正在为我的项目使用Ironpython。 但是,当我尝试使用C#动态类型调用下面代码中的函数时,它会编译,但我从内部得到以下错误: “Assets/Scripts/WordSearchAlgorithm.cs(37,29):错误CS1502: System.Runtime.CompilerServices.CallSite,对象>>。创建(System.Runtime.CompilerServices.CallSiteBinder)'
System.Runtime.CompilerServices.CallSite,对象>>。创建(System.Runtime.CompilerServices.CallSiteBinder)' 具有一些无效参数“”
Assets/Scripts/WordSearchAlgorithm.cs(37,29):错误CS1503:参数
“#1”无法将“object”表达式转换为类型
“System.Runtime.CompilerServices.CallSiteBinder'”
Assets/Scripts/WordSearchAlgorithm.cs(37,61):错误CS0234:类型
或命名空间名称“RuntimeBinder”在命名空间中不存在
`Microsoft.CSharp。是否缺少程序集引用?
Assets/Scripts/WordSearchAlgorithm.cs(37,61):错误CS1502:最佳
“System.Runtime.CompilerServices.CallSite>.Create(System.Runtime.CompilerServices.CallSiteBinder)”的重载方法匹配具有一些无效参数 我认为mono不支持这个。你能给我一个解决方案来帮助我吗
static public void StartSearchAlgorithm()
{
List < string > myList = new List < string > ()
{
"fxie",
"amlo",
"ewbx",
"astu"
};
var ironPythonRuntime = Python.CreateRuntime();
try
{
//Load the Iron Python file/script into the memory
//Should be resolve at runtime
dynamic loadIPython = ironPythonRuntime.UseFile("C:/py.py");
//Invoke the method and print the result
loadIPython.BoggleWords(myList, loadIPython.MakeTrie("C:/words.txt")); // here is my problem to calling function from python that unity logError
// Debug.Log(string.Format("dd", loadIPython.BoggleWords(myList, loadIPython.MakeTrie("C:/words.txt"))));
}
catch (FileNotFoundException ex)
{}
}
static public void StartSearchAlgorithm()
{
列表myList=新列表()
{
“fxie”,
“反洗钱组织”,
“ewbx”,
“阿斯图”
};
var ironPythonRuntime=Python.CreateRuntime();
尝试
{
//将Iron Python文件/脚本加载到内存中
//应该在运行时解析
动态loadIPython=ironPythonRuntime.UseFile(“C:/py.py”);
//调用该方法并打印结果
loadIPython.BoggleWords(myList,loadIPython.MakeTrie(“C:/words.txt”);//我的问题是从python调用该函数时出现了错误
//Log(string.Format(“dd”,loadIPython.BoggleWords(myList,loadIPython.MakeTrie(“C:/words.txt”)));
}
捕获(FileNotFoundException ex)
{}
}
Unity使用.NET的Mono 2.0版本,与.NET 3.5类似<代码>动态是在中引入的,因此Unity可能不会编译
在播放器设置中可以选择将Mono 2.0 sub更改为Mono 2.0 full,但我不知道它是否支持动态
。至少你可以试试
我正在尝试在播放器设置中将Mono 2.0 sub更改为Mono 2.0 full,但仍然存在错误,因此Mono 2.0不支持此操作。也可以看到这个答案:谢谢Marnix的回答,我以前看过这个主题,但喜欢上面的代码。我想调用我的Python函数,如果不使用C#动态类型就无法工作。我不知道是否应该更改我的编码。你能找到一个使用.NET3.5的IronPython库吗?我使用了C#4.0中的IronPython 2.6,但unity的库有错误