繁体   English   中英

MonoTouch C# 和 Obj-C 混用?

[英]MonoTouch C# and Obj-C mixing?

继上一个关于优化的问题之后,我发现更容易相信根本不可能进一步优化我的代码以在我的游戏中获得更好的性能。

所以现在我有了一个新想法,想知道它是否可能甚至值得实施。 Since the clear bottleneck in performance is from the physics processing which is based in .net, I was thinking, would it be possible to fit in an objective-c or C++ based physics engine (such as box2D) to interact with Mono?

例如,在 Mono 代码中,我会执行 CreateBox() 之类的操作,但在幕后,盒子是在 Obj-C/C++ 中创建的。 或者,当我进行物理更新时,我只需在 Mono 中调用 function 并且首当其冲的工作发生在 Obj-C/C++

如果这是可能的,任何人都可以指出我正确的开始方向吗?

是的。

有两种方法可以做到这一点,通过 C API 和 Objective-C ZDB974238714CA8DE634ACE14

With a C API, write your native code in C (or C++ with extern "C" ), compile your code into a static library, link your MonoTouch app against the static library , then use P/Invoke to access your C functions. 但是,与需要指定库名称的“普通”P/Invoke 不同,您需要指定"__Internal"作为库名称:

[DllImport ("__Internal")]
static extern void MethodInStaticLibrary ();

MonoTouch 使用相同的技术从例如System.dll调用到 MonoTouch 运行时。

使用 Objective-C 是相同但不同的。 Instead of a static library exporting a C ABI, you need a static library exporting an Objective-C ABI, link against the static library, then provide an API binding for your Objective-C library .

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM