webgl unity_Unity WebGL中的低级插件

webgl unity

Last year we launched a series of technical blog posts on WebGL, starting with a couple of posts on memory. Now it’s time to continue with a new topic. Have you ever needed/wanted to re-use existing C/C++ code in a web page? Perhaps a graphics effect written in OpenGL ES? With Unity WebGL there is a way!

去年,我们在WebGL上发布了一系列技术博客文章,从内存中的几篇文章开始。 现在是时候继续一个新主题了。 您是否曾经需要/想要重复使用网页中的现有C / C ++代码? 也许是用OpenGL ES编写的图形效果? 有了Unity WebGL,就有了一种方法!

Unity supports two types of plugins: managed and native. On WebGL, managed plugins are supported like on other platforms. The only difference is that the managed assembly of the plug-in is converted, along with the engine and user’s managed code, to JavaScript (asm.js/wasm to be specific).

Unity支持两种类型的插件 :托管和本机。 与其他平台一样, 在WebGL上 也支持 托管插件 。 唯一的区别是,插件的托管程序集与引擎和用户的托管代码一起转换为JavaScript(具体来说为asm.js / wasm)。

What about native plugins? Does it even make sense to talk about something “native” on the web? When referring to native as something specific to the underlying architecture (mac, win32/64, etc.), it certainly does not. However, Unity WebGL does support several other types of plugins: JavaScript, C/C++ and pre-compiled LLVM byte code.

本机插件 呢? 在网络上谈论“本机”甚至有意义吗? 当将native称为特定于基础架构的东西(mac,win32 / 64等)时,它当然不是。 但是,Unity WebGL确实支持其他几种类型的插件:JavaScript,C / C ++和预编译的LLVM字节码。

In the Unity User Manual, there are a couple of examples of both JavaScript and C plugins that demonstrate how to interact with them via scripts. So, since we can use C/C++ sources, what’s stopping us from accessing the Low-Level plugin interface for rendering purposes? Well… nothing in Unity 5.5 ;-)

在Unity 用户手册中 ,有两个JavaScript和C插件示例,它们演示了如何 通过脚本与它们进行 交互 。 因此,由于我们可以使用C / C ++源,是什么阻止了我们 出于渲染目的而 访问 Low-Level插件接口 ? 好吧... Unity 5.5中什么都没有;-)

In fact, Unity 5.5 adds the missing hooks to allow you to register a low-level plugin:

实际上,Unity 5.5添加了缺少的钩子,以允许您注册低级插件:

As you can see, the amount of code we had to add is massive. Now let’s see what you need to do to implement your plug-in!

如您所见,我们必须添加大量的代码。 现在,让我们看看实现插件所需要做的!

实作 (Implementation)

First of all, you need to copy the Plugin API headers from the Unity install path Editor/Data/PluginAPI to the location that will contain your plug-in source file(s).

首先,您需要将Unity安装路径Editor / Data / PluginAPI中的Plugin API标头复制到将包含您的插件源文件的位置。

The headers you are interested in are IUnityInterface.h and IUnityGraphics.h, which declare the interfaces needed for the plugin. Remember that these headers are specific to a version of Unity, so it’s important to keep them in sync with the Editor.

您感兴趣的标头是IUnityInterface.hIUnityGraphics.h ,它们声明了插件所需的接口。 请记住,这些标头特定于Unity版本,因此使它们与编辑器保持同步很重要。

The function you need to call to register your plugin is UnityRegisterRenderingPlugin:

注册插件需要调用的函数是UnityRegisterRenderingPlugin

1

extern "C" void UnityRegisterRenderingPlugin(PluginLoadFunc loadPlugin, PluginUnloadFunc unloadPlugin);

1

extern "C" void UnityRegisterRenderingPlugin ( PluginLoadFunc loadPlugin , PluginUnloadFunc unloadPlugin ) ;

However, first you need to implement both Load and Unload callbacks to get the IUnityGraphics interface and register/unregister the graphics device event callback for your low-level rendering. Here is an example:

但是,首先,您需要同时实现LoadUnload回调,以获取IUnityGraphics接口并为低级渲染注册/注销图形设备事件回调。 这是一个例子:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值