The process to call code in native plug-ins for Android is the same as standard native plug-ins.
Note: If you use individual C/C++ source files as plug-ins, use __Internal
as the plug-in name in the DllImport attribute.
It’s best practice to wrap all native plug-in method calls with an additional C# code layer that:
The AndroidNativePlugin.unitypackage zip file contains a simple example of a native code plug-in distributed as a Unity package.
The sample shows how to invoke C++ code from a Unity application. The package includes a scene which displays the sum of two values as calculated by a native plug-in. To compile the plug-in, use Android NDK. For information on how to install Android NDK via the Unity Hub, see Android environment setup.
要安装该示例,请执行以下操作:
AndroidNativePlugin.unitypackage
file.AndroidNativePlugin.unitypackage
file.