This page describes Native Code Plugins for the Tizen platform.
1.在 C# 文件中定义 extern 方法,如下所示:
[DllImport ("PluginName")]
private static extern float FooPluginFunction();
#include <tizen.h>
EXPORT_API float FooPluginFunction();
If you are using C++ (.cpp) to implement the plugin you must ensure the functions are declared with C linkage to avoid name mangling issues.
extern "C" {
EXPORT_API float FooPluginFunction();
}
Plugins written in C do not need this since these languages do not use name-mangling.
Once built, the shared library should be copied to the Assets->Plugins->Tizen->libs folder. Unity will then find it by name when you define a function like the following in the C# script:
[DllImport ("PluginName")]
private static extern float FooPluginFunction ();
Please note that PluginName should not include the prefix (‘lib’) nor the extension (‘.so’) of the filename. You should wrap all native code methods with an additional C# code layer. This code should check Application.platform and call native methods only when the app is running on the actual device; dummy values can be returned from the C# code when running in the Editor. You can also use platform defines to control platform dependent code compilation.
Unity Tizen supports limited native-to-managed callback functionality via UnitySendMessage:
UnitySendMessage("GameObjectName1", "MethodName1", "Message to send");
This function has three parameters : the name of the target GameObject, the script method to call on that object and the message string to pass to the called method.
已知限制:
1.只能从本机代码调用与以下签名对应的脚本方法:function MethodName(message:string)
1.对 UnitySendMessage 的调用是异步的,并有一帧延迟。