Create a native plug-in for iOS and import it into your Unity project.
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();
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
}
Add your native source files to your project’s Assets folder.
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.