Create a native plug-in for iOS
Create a native plug-in for your iOS project and import it into Unity.
Read time 1 minuteLast updated 12 days ago
Create a native plug-in for iOS and import it into your Unity project.
Define an extern method
For each native function you want to call, define an method in the C# file as follows:
extern[DllImport ("__Internal")]private static extern float FooPluginFunction();
Use C linkage to prevent name mangling
If you use C++ () or Objective-C++ () for your plug-in, declare functions with C linkage to avoid name mangling:
.cpp.mmextern "C" { float FooPluginFunction();}
C or Objective-C plug-ins don’t require C linkage as they don’t use name mangling.
If you use Swift for your plug-in, use the attribute to export functions with C linkage and avoid name mangling:
@_cdecl@_cdecl("FooPluginFunction")func AnythingFooPluginFunction() -> Float { return 3.14}
Import your native plug-in into your Unity project
Add your native source files to your project's folder.
AssetsConfigure plug-in settings
Use the Inspector window to configure your plug-in so Unity includes it in the generated Xcode project. Refer to Configure a plug-in for iOS with the Inspector window for details.