Version: Unity 6.6 Alpha (6000.6)
Language : English
Introduction to native plug-ins on iOS
Call native plug-ins for iOS

Create a native plug-in for iOS

Create a native plug-inA set of code created outside of Unity that creates functionality in Unity. There are two kinds of plug-ins you can use in Unity: Managed plug-ins (managed .NET assemblies created with tools like Visual Studio) and Native plug-ins (platform-specific native code libraries). More info
See in Glossary
for iOS and import it into your Unity project.

Define an extern method

For each native function you want to call, define an extern method in the C# file as follows:

Note: Use "__Internal" as the library name when your native code is built into the same binary as the Unity runtime. For example, a statically linked plug-in. If your native code is in a dynamic library (.dylib), use the library name instead. For example, "MyPlugin" for MyPlugin.dylib.

[DllImport ("__Internal")]

private static extern float FooPluginFunction();

Use C linkage to prevent name mangling

If you use C++ (.cpp) or Objective-C++ (.mm) for your plug-in, declare functions with C linkage to avoid name mangling:

extern "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 @_cdecl attribute to export functions with C linkage and avoid name mangling:

@_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 Assets folder.

Configure plug-in settings

Use the InspectorA Unity window that displays information about the currently selected GameObject, asset or project settings, allowing you to inspect and edit the values. More info
See in Glossary
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.

Additional resources

Introduction to native plug-ins on iOS
Call native plug-ins for iOS