unity 脚本加载脚本_Unity中脚本的未来

unity 脚本加载脚本_Unity中脚本的未来

unity 脚本加载脚本

Recently we talked about Unity and WebGL. In that post we briefly spoke about how scripting works in WebGL, using new technology called “IL2CPP”. However, IL2CPP represents a lot more than just a scripting solution for WebGL; it’s our own high performance .NET Runtime, to be rolled out on more platforms.

最近, 我们谈论了Unity和WebGL 。 在那篇文章中,我们简要介绍了如何使用称为“ IL2CPP”的新技术在WebGL中编写脚本。 但是,IL2CPP所代表的不仅仅是WebGL的脚本解决方案。 这是我们自己的高性能.NET Runtime,将在更多平台上推出。

But before we delve into the future, let’s talk about the present.

但是,在我们深入探讨未来之前,让我们先谈一下现在。

今天在Unity中编写脚本 (Scripting in Unity today)

We leverage Mono (and WinRT on Windows Store Apps and Windows Phone) to bring the ease of use of C#, access to 3rd party libraries, and near native performance to Unity. However, there are some challenges:

我们利用Mono (以及Windows Store Apps和Windows Phone上的WinRT )为C#的易于使用,对第三方库的访问以及Unity的接近本机性能。 但是,存在一些挑战:

  • C# runtime performance still lags behind C/C++

    C#运行时性能仍然落后于C / C ++
  • Latest and greatest .NET language and runtime features are not supported in Unity’s current version of Mono.

    Unity的当前Mono版本不支持最新,最出色的.NET语言和运行时功能。

  • With around 23 platforms and architecture permutations, a large amount of effort is required for porting, maintaining, and offering feature and quality parity.

    大约有23种平台和体系结构排列,移植,维护以及提供功能和质量奇偶校验需要大量的精力。
  • Garbage collection can cause pauses while running

    垃圾收集在运行时可能导致停顿

These issues have remained in the front of our minds over the past few years as we sought to address them. Concurrently, investigations into supporting scripting for WebGL were occurring. As each progressed forward, these two paths converged into a single approach.

在过去的几年中,我们一直试图解决这些问题。 同时,正在对支持WebGL的脚本进行调查。 随着各自的发展,这两个路径融合为一种方法。

With the problem scope clear, experimentation on different ways to solve this were tried. Some of them were promising; others were not. But ultimately we found an innovative solution and it proved to be the right way forward.

在明确问题范围的情况下,尝试了各种解决方案。 其中一些人很有前途; 其他不是。 但是最终我们找到了创新的解决方案,事实证明这是正确的方法。

That way forward is IL2CPP.

前进的方向是IL2CPP。

IL2CPP:快速而肮脏的介绍 (IL2CPP: the quick and dirty intro)

IL2CPP consists of two pieces: an Ahead of Time (AOT) compiler and a Virtual Machine (VM).

IL2CPP由两部分组成: Ahead of Time(AOT)编译器Virtual Machine(VM)

These two parts represent our own implementation of the Common Language Infrastructure, similar to .NET or Mono. It is compatible with the current scripting implementation in Unity.

这两个部分代表我们自己的通用语言基础结构实现 ,类似于.NET或Mono。 它与Unity中的当前脚本实现兼容。

Fundamentally, it differs from the current implementation in that the IL2CPP compiler converts assemblies into C++ source code. It then leverages the standard platform C++ compilers to produce native binaries.

从根本上讲,它与当前实现的不同之处在于IL2CPP编译器将程序集转换为C ++源代码。 然后,它利用标准平台的C ++编译器生成本机二进制文件。

At runtime this code is executed with additional services (like a GC, metadata, platform specific resources) that are provided by the IL2CPP VM.

在运行时,该代码与IL2CPP VM提供的其他服务(例如GC,元数据,特定于平台的资源)一起执行。

IL2CPP的好处。 (The benefits of IL2CPP.)

Let’s talk about each one of the previously mentioned issues and how IL2CPP addresses each of them.

让我们讨论一下前面提到的每个问题以及IL2CPP如何解决每个问题。

性能 (Performance)

IL2CPP seeks to provide the ease of use and productivity of C# with the performance of C++.

IL2CPP力求通过C ++的性能来提供C#的易用性和生产率。

It allows the current, productive scripting workflow to remain the same while giving an immediate performance boost. We’ve seen 2x-3x performance improvements in some of our script-heavy benchmarks. This performance boost is due to a few reasons.

它可以使当前高效的脚本工作流程保持不变,同时可以立即提高性能。 在一些脚本繁重的基准测试中,我们已经看到2到3倍的性能提升。 这种性能提升是由于一些原因。

  • C++ compilers and linkers provide a vast array of advanced optimisations previously unavailable.

    C ++编译器和链接器提供了许多以前无法使用的高级优化。
  • Static analysis is performed on your code for optimisation of both size and speed.

    对您的代码执行静态分析,以优化大小和速度。
  • Unity-focused optimisations to the scripting runtime.

    针对脚本运行时的以Unity为重点的优化。

While IL2CPP is definitely still a work in progress, these early performance gains are indicative of great things to come.

尽管IL2CPP肯定仍在开发中,但这些早期的性能提升预示着未来的发展。

.NET升级 (.NET Upgrade)

A very frequent request we get is to provide an upgraded runtime. While .NET has advanced over the past years, Unity currently supports .NET 2.0/3.5 era functionality for both the C# compiler and the class libraries. Many users have requested access to newer features, both for their code as well as 3rd party libraries.

我们经常收到的要求是提供升级的运行时。 在过去几年中,.NET取得了进步,而Unity目前为C#编译器和类库支持.NET 2.0 / 3.5时代的功能。 许多用户都要求访问其代码以及第三方库的更新功能。

To complement IL2CPP, as it matures, we will also be upgrading to recent versions of the Mono C# compiler, base class libraries, and runtime for use in the editor (The editor will not switch to IL2CPP, for fast iteration during development). These two things combined will bring a modern version of .NET to Unity.

为了补充成熟的IL2CPP,我们还将升级到Mono C#编译器,基类库和运行时的最新版本,以便在编辑器中使用(编辑器将不会切换到IL2CPP,以便在开发过程中进行快速迭代)。 这两件事的结合将为Unity带来现代版本的.NET。

It’s also important to note that we are collaborating with Microsoft to bring current and future .NET functionality to Unity, ensuring compatibility and quality.

还需要注意的是,我们正在与Microsoft合作,将当前和将来的.NET功能引入Unity,以确保兼容性和质量。

便携性和维护 (Portability and Maintenance)

While this area may sound like an internal issue for Unity to deal with, it also affects you. The Mono virtual machine has extensive amounts of platform and architecture specific code. When we bring Unity to a new platform, a large amount of our effort goes into porting and maintaining the Mono VM for that platform. Features (and bugs) may exist on some platforms but not others. This affects the value which Unity strives to provide to you; easy deployment of the same content to different platforms.

虽然这似乎是Unity需要解决的内部问题,但它也会影响您。 Mono虚拟机具有大量平台和体系结构特定的代码。 当我们将Unity引入新平台时,我们将花费大量精力来为该平台移植和维护Mono VM。 功能(和错误)可能在某些平台上存在,但在其他平台上不存在。 这会影响Unity努力为您提供的价值; 轻松将相同内容部署到不同平台。

IL2CPP addresses these issues in a number of ways:

IL2CPP以多种方式解决这些问题:

  • All code generation is done to C++ rather than architecture specific machine code. The cost of porting and maintenance of architecture specific code generation is now more amortised.

    所有代码生成都是针对C ++完成的,而不是针对特定体系结构的机器代码。 移植和维护特定于体系结构的代码生成的成本现在要分摊。
  • Feature development and bug fixing proceed much faster. For us, days of mucking in architecture specific files are replaced by minutes of changing C++. Features and bug fixes are immediately available for all platforms. In it’s current state, IL2CPP support is being ported to new platforms in short amount of time.

    功能开发和错误修复的速度要快得多。 对我们来说,仅花费几分钟的时间更改C ++就可以取代特定于体系结构的文件的日子。 功能和错误修复可立即用于所有平台。 在当前状态下,IL2CPP支持将在短时间内移植到新平台。

Additionally, platform or architecture specific compilers can be expected to optimise much better than a singular code generator. This allows us to reuse all the effort that has gone into the C++ compilers, rather than reinventing it ourselves.

此外,可以期望平台或体系结构特定的编译器比单个代码生成器的优化要好得多。 这使我们可以重用C ++编译器的所有工作,而不是自己重新发明。

垃圾收集 (Garbage Collection)

IL2CPP is not tied to any one specific garbage collector, instead interacting with a pluggable API. In its current iteration IL2CPP uses an upgraded version of libgc, even as we look at multiple options. Aside from just the GC itself, we are investigating reducing GC pressure by analysis done in the IL2CPP compiler.

IL2CPP没有绑定到任何一个特定的垃圾收集器,而是与可插入的API进行交互。 在当前的迭代中,IL2CPP使用libgc的升级版本,即使我们查看多个选项也是如此。 除了GC本身以外,我们还在研究通过IL2CPP编译器进行的分析来降低GC压力。

While we don’t have a lot more to share at the moment, research is ongoing. We know this is important to many of you, we’ll continue working on it and keep you informed in future blog posts. Unrelated to IL2CPP, but worth mentioning in the context of garbage collection, Unity 5 will see more and more allocation free APIs.

尽管我们目前没有太多要分享的内容,但研究仍在进行中。 我们知道这对你们中的许多人很重要,我们将继续努力,并在以后的博客文章中向您通报情况。 与IL2CPP无关,但是值得一提的是垃圾回收,Unity 5将看到越来越多的免费分配API。

IL2CPP不是什么 (What IL2CPP is not)

IL2CPP is not recreating the whole .NET or Mono toolchain. We will continue to use the Mono C# compiler (and perhaps later, Roslyn). We will continue to use the Mono class libraries. All currently supported features and 3rd party libraries which work with Mono AOT should continue to work with IL2CPP. We are only seeking to provide a replacement for the Mono VM and AOT compiler, and will keep on leveraging the wonderful Mono Project.

IL2CPP不会重新创建整个.NET或Mono工具链。 我们将继续使用Mono C#编译器 (也许以后使用Roslyn )。 我们将继续使用Mono类库。 与Mono AOT一起使用的所有当前支持的功能和第三方库应继续与IL2CPP一起使用。 我们仅寻求替代Mono VM和AOT编译器,并将继续利用出色的Mono Project

我什么时候可以尝试IL2CPP? (When can I try IL2CPP?)

By now we hope you are just as excited as we are to use IL2CPP and wondering when you can get your hands on it! An early version of IL2CPP will be available as part of WebGL publishing in Unity 5.

现在,我们希望您和使用IL2CPP一样兴奋,并想知道何时可以使用它! IL2CPP的早期版本将作为Unity 5中WebGL发布的一部分提供。

Beyond WebGL, we are continuing development of IL2CPP for other platforms. In fact, we already have working implementations on a number of our supported platforms. We expect to be rolling out at least one additional platform later this year. Our current plan is to have iOS be the next platform shipping with IL2CPP support.

除了WebGL,我们还在继续为其他平台开发IL2CPP。 实际上,我们已经在许多受支持的平台上实现了有效的实现。 我们预计今年晚些时候将推出至少一个额外的平台。 我们当前的计划是使iOS成为支持IL2CPP的下一个平台。

The planned upgrades of our Mono toolchain will follow after IL2CPP is available on more platforms and has matured.

IL2CPP在更多平台上可用并已经成熟之后,将进行Mono工具链的计划升级。

One platform that will never be supported by IL2CPP is the WebPlayer; this is due to security implications. And as noted earlier, the editor will remain to be using Mono.

WebPlayer是IL2CPP永远不会支持的平台。 这是由于安全隐患。 如前所述,编辑器将继续使用Mono。

Additionally, you can see the IL2CPP runtime in action today. As mentioned, the two WebGL demos we posted are IL2CPP-powered.

另外,您可以今天看到IL2CPP运行时的运行。 如前所述, 我们发布两个WebGL演示都是由IL2CPP驱动的。

下一步是什么? (What’s next?)

We are still hard at work on IL2CPP: implementing new features, optimising code generation, fixing bugs, and supporting more platforms. We’ll keep posting more in-depth blogs as we make progress and talk about it with you on the forums.

我们在IL2CPP方面仍在努力工作:实现新功能,优化代码生成,修复错误以及支持更多平台。 随着我们的进步,我们将继续发布更多深入的博客,并在论坛上与您讨论

The Scripting Team.

脚本团队。

翻译自: https://blogs.unity3d.com/2014/05/20/the-future-of-scripting-in-unity/

unity 脚本加载脚本