编程语言
首页 > 编程语言> > 在Unity 5.3.1f中使用C#动态类型

在Unity 5.3.1f中使用C#动态类型

作者:互联网

参见英文答案 > Use the dynamic keyword/.NET 4.6 feature in Unity                                    1个
我为我的游戏编写了代码,需要运行我的python代码.我正在为我的项目使用Ironpython.
但是,当我尝试使用C#动态类型来调用下面的代码中的函数时,它会编译但是我从内部传递得到以下错误:

” Assets/Scripts/WordSearchAlgorithm.cs(37,29): error CS1502:
The best overloaded method match for
System.Runtime.CompilerServices.CallSite,object>>.Create(System.Runtime.CompilerServices.CallSiteBinder)’
has some invalid arguments ” “
Assets/Scripts/WordSearchAlgorithm.cs(37,29): error CS1503: Argument
‘#1’ cannot convert ‘object’ expression to type
‘System.Runtime.CompilerServices.CallSiteBinder’ ” “
Assets/Scripts/WordSearchAlgorithm.cs(37,61): error CS0234: The type
or namespace name ‘RuntimeBinder’ does not exist in the namespace
`Microsoft.CSharp’. Are you missing an assembly reference? “
Assets/Scripts/WordSearchAlgorithm.cs(37,61): error CS1502: The best
overloaded method match for ‘System.Runtime.CompilerServices.CallSite>.Create(System.Runtime.CompilerServices.CallSiteBinder)’ has some invalid arguments

我认为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)
    {}
}

解决方法:

Unity使用的是Mono 2.0版本的.NET,类似于.NET 3.5.动态是在.NET 4.0中引入的,因此Unity可能无法编译.

可以选择在播放器设置中将Mono 2.0 sub更改为Mono 2.0 full,但我不知道它是否支持动态.至少你可以试试.

enter image description here

标签:c,unity3d,ironpython,dynamic-typing
来源: https://codeday.me/bug/20190702/1355143.html