このページは プラグイン の iOS プラットフォーム版について説明します。
[DllImport ("__Internal")]
private static extern float FooPluginFunction();
もし C++( .cpp )もしくは Objective-C++( .mm )を使用してプラグインを実装している場合、Name Mangling の問題を避けるため、C リンケージ( C linkage )で宣言されている事を確認する必要があります。
extern "C" {
float FooPluginFunction();
}
C または Objective-C で書かれたプラグインは、言語で Name Mangling を使用しないため、これを使用する必要がありません。
ネイティブプラグインは実際のデバイス展開時にのみ呼び出すことができるので、すべてのネイティブプラグインは C# コードレイヤーでメソッドをラップすることをお勧めします。このコードは Application.platform でデバイス上で動作しているか確認し、動作中のときのみネイティブメソッドを呼び出します。また、エディター上で動作しているときダミーの値を返すことができます。例えば、Bonjour browser のサンプルコードを参照してください。
Unity iOS は、“UnitySendMessage” を媒介に、限定的なネイティブからマネージコードへのコールバック( native-to-managed callback )をサポートしています:
UnitySendMessage("GameObjectName1", "MethodName1", "Message to send");
この関数は 3 つのパラメーターを持っています。ターゲットである GameObject の名前、そのオブジェクトに対して呼び出すスクリプトメソッド、呼び出されたメソッドに渡すメッセージの文字列、です。
以下の制限が知られています。
function MethodName(message:string)
Unity iOS は自動化されたプラグインの統合を制限された範囲でサポートしています。Assets/Plugins/iOS__に配置した .a,.m,.mm,.c,.cpp__ の拡張子を持つすべてのファイルは、自動的に Xcode プロジェクトにマージされます。ただし、マージは最終的には Assets/Plugins/iOS からのシンボリックリンクファイル(symlinking files)によって、マージ先に行われます。これは一部のワークフローに影響を与える可能性があります。.h ファイルは Xcode のプロジェクトツリーに含まれていません。しかし、マージ先のファイルシステムには表示されるので、.m/.mm/.c/.cpp ファイルのコンパイルを可能にします。
注意: サブフォルダーは現在サポートされていません
ネイティブコードプラグインの簡単な使用例は、ここ を探してください。
このサンプルでは、Unity の iOS アプリケーションから Objective-C のコードを呼び出す方法を示します。このアプリケーションは非常に簡単な Bonjour のクライアントを実装しています。 アプリケーションは、Unity iOS のプロジェクトとネイティブコードで構成されています。それはビルドした XCode プロジェクトに追加する必要があります。 アプリケーションは Unity iOS プロジェクト( Plugins/Bonjour.cs はネイティブコードの C# インターフェースです。BonjourTest.js はアプリケーションロジックを実装する JS スクリプトです。)とネイティブコード( Assets/Code )で構成されています。 そしてそれらをビルドして Xcode プロジェクトへ追加します。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.