ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

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

2019-07-02 09:51:39  阅读:545  来源: 互联网

标签:c unity3d ironpython dynamic-typing


参见英文答案 > 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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有