簡體   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