查看: 1967|回复: 0
打印 上一主题 下一主题

unity3d web player的限制

[复制链接]

5552

主题

2

听众

8万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
11

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

跳转到指定楼层
楼主
发表于 2012-3-10 11:25:35 |只看该作者 |倒序浏览
Plugins (Pro/Mobile-Only Feature)
Unity has extensive support for Plugins, which are libraries of native code written in C, C++, Objective-C, etc. Plugins allow your game code (written in Javascript, C# or Boo) to call functions from these libraries. This feature allows Unity to integrate with middleware libraries or existing C/C++ game code.
Note: On the desktop platforms, plugins are a pro-only feature. For security reasons, plugins are not usable with webplayers.
In order to use a plugin you need to do two things:-
Write functions in a C-based language and compile them into a library.

Create a C# script which calls functions in the library.

The plugin should provide a simple C interface which the C# script then exposes to other user scripts. It is also possible for Unity to call functions exported by the plugin when certain low-level rendering events happen (for example, when a graphics device is created), see the Native Plugin Interface page for details.
Here is a very simple example:
C File of a Minimal Plugin:

float FooPluginFunction () { return 5.0F; }
C# Script that Uses the Plugin:

using UnityEngine;

using System.Runtime.Interopservices;
class SomeScript : MonoBehaviour {
   #if UNITY_IPHONE || UNITY_XBOX360
   // On iOS and Xbox 360 plugins are statically linked into

   // the executable, so we have to use __Internal as the

   // library name.

   [DllImport ("__Internal")]
   #else
   // Other platforms load plugins dynamically, so pass the name

   // of the plugin's dynamic library.

   [DllImport ("luginName")]
   #endif
   private static extern float FooPluginFunction ();
   void Awake () {

      // Calls the FooPluginFunction inside the plugin

      // And prints 5 to the console

      print (FooPluginFunction ());

   }

}

Note that when using Javascript you will need to use the following syntax, where DLLName is the name of the plugin you have written, or "__Internal" if you are writing statically linked native code:
@DllImport (DLLName)

static private function FooPluginFunction () : float {};

Creating a Plugin

In general, plugins are built with native code compilers on the target platform. Since plugin functions use a C-based call interface, you must avoid name mangling issues when using C++ or Objective-C.
For further details and examples, see the following pages:-
Building Plugins for Desktop Platforms

Building Plugins for iOS

Building Plugins for Android

Further Information

Native Plugin Interface - this is needed if you want to do rendering in your plugin.

Mono Interop with native libraries.

P-invoke documentation on MSDN.
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2025-6-12 04:30 , Processed in 0.070053 second(s), 28 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部