Version: 5.6
Features currently not supported by Unity Tizen
Tizen Emulator

Building Plugins for Tizen

This page describes Native Code Plugins for the Tizen platform.

Building an Application with a Native Plugin for Tizen

1.在 C# 文件中定义 extern 方法,如下所示:

[DllImport ("PluginName")]
private static extern float FooPluginFunction();
  1. Set the editor to the Tizen build target
  2. Create a Tizen Native Shared Library project from the Tizen IDE.
  3. All native functions that you want to use from managed code need to have the EXPORT_API attribute added to their definitions. The header tizen.h also needs to be included for access to the EXPORT_API macro.
#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.

Using Your Plugin from C#

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.

Calling C# / JavaScript back from native code

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 的调用是异步的,并有一帧延迟。

Features currently not supported by Unity Tizen
Tizen Emulator