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.
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 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.