![](/img/trans.png)
[英]How can i send information from two different arduino boards to unity 3d c#
[英]How can I include SWIG-wrapped C++ in Unity 3D?
我的目標是使用SWIG封裝玩具C ++庫,並且可以訪問Unity中的C#/ Mono腳本。 (換句話說,讓圖書館功能在游戲的Windows版本中運行。我將在下一步處理Android :)
我一直在關注Build a C#模塊 (SWIG教程), Unity和DLL (Eric Eastwood)以及SWiG for Visual Studio項目入門 (技術食譜)的組合。 我在Visual Studio 2013中生成了兩個DLL,並將它們添加到Unity項目中。 但是在運行時訪問玩具方法失敗了。
我遵循的步驟(包括我收到的錯誤的常見修復):
創建C ++項目/自定義構建
創建C#項目
using System;
using System.Runtime.InteropServices;
namespace CSharpExampleLib {
...
}
構建兩個Release DLL
CorFlags
強制C#DLL為32位(引用) (這不起作用/不適用於C ++ DLL) 將DLL添加到Unity項目
using System.Runtime.InteropServices;
using System.IO;
從DLL調用方法
最后,我添加了從簡單腳本到C#DLL的日志記錄調用(Intellisense確認可以訪問DLL和方法):
Debug.Log(CSharpExampleLib.example.fact(3));
// should log the result of 3 factorial
運行時錯誤
但是,當我從Unity編輯器啟動游戲時,我收到以下錯誤:
DllNotFoundException: example
CSharpExampleLib.examplePINVOKE+SWIGExceptionHelper..cctor ()
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for SWIGExceptionHelper
CSharpExampleLib.examplePINVOKE..cctor ()
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for CSharpExampleLib.examplePINVOKE
CSharpExampleLib.example.fact (Int32 n)
SimpleController.Start () (at Assets/scripts/SimpleController.cs:10)
我做了幾次嘗試來糾正這個錯誤的常見原因(構建為Release,構建為32位,檢查Dependency Walker等)無濟於事。 是否有某些SWIG或Unity特定的東西我缺少? 我可以在我的DLL上執行的任何其他檢查?
在對SWIG用戶郵件列表進行討論並仔細審查后,我發現我缺少兩個配置步驟:
C ++ DLL必須與SWIG接口文件中指定的模塊名稱相同(因此對於使用接口文件example.i的玩具示例,最好將C ++項目命名為“example”,它將生成example.dll)
在解決其他問題的后退和前進中,我丟失了對自動生成的C ++包裝器(example_wrap.cxx)的引用,需要將其重新添加到C ++項目中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.