2016-03-18 65 views
4

我已經寫了代碼爲我的遊戲,需要運行我的Python代碼的功能。我正在爲我的項目使用Ironpython。 然而,當我試圖用C#動態類型調用一個函數在下面的代碼,它編譯,但我從內幕以下錯誤:使用C#動態類型在Unity 5.3.1f

「資產/腳本/ WordSearchAlgorithm.cs(37, 29):錯誤CS1502: 最佳重載的方法匹配
System.Runtime.CompilerServices.CallSite,對象>>創建(System.Runtime.CompilerServices.CallSiteBinder)」 有一些無效參數 「」
資產/腳本/WordSearchAlgorithm.cs(37,29):錯誤CS1503:參數
'#1' 不能轉換 '對象' 表達鍵入
'System.Runtime.CompilerServices.CallSiteBinder' 「」
資產/腳本/ WordSearchAlgorithm.cs(37,61):錯誤CS0234:類型
或命名空間名稱RuntimeBinder'不存在命名空間中存在
`微軟.CSharp」。您是否缺少裝配參考? 「
資產/腳本/ WordSearchAlgorithm.cs(37,61):錯誤CS1502:最好的
重載的方法匹配'System.Runtime.CompilerServices.CallSite> .Create(System.Runtime.CompilerServices.CallSiteBinder)'有一些無效的參數

我認爲單不支持此,請你給我一個解決方案,以幫助我嗎?

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) 
    {} 
} 

回答

2

統一使用單聲道2.0版本的.NET的,這是類似的。 NET 3.5。dynamic.NET 4.0推出,所以統一將可能不是C ompile。

有改變單聲道2.0分至2.0單全在玩家設置的選項,但我不知道這是否支持dynamic。至少你可以試試。

enter image description here

+0

我試圖改變單聲道2.0分至2.0單全在播放器設置,但錯誤依然存在 –

+0

那麼它是不是在單聲道2.0的支持。之前,但像代碼http://answers.unity3d.com/questions/686244/using-c-dynamic-typing-with-unity-434f1.html – Marnix

+0

感謝馬尼克斯爲您答疑,我看到了這個話題:又見這個答案以上。我想調用我的Python函數,而不使用C#動態類型不起作用。我不知道也許應該改變我的編碼 –