![](/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.