如何区分mono 和mono2x il2cppp

我的unity 5里,怎么没有IL2CPP选项 ?
我的unity 5里,怎么没有IL2CPP选项 ?应该在scripting backend有这个选项,但是我只有mono(2.x)这一个选项?
安装时选择平台的时候应该有相关选项
已有帐号?
无法登录?
社交帐号登录Navigation
Unity Account
You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio.
An introduction to IL2CPP internals
, May 6, 2015 in
Almost a year ago now, we started to talk about the
of scripting in Unity. The new IL2CPP scripting backend promised to bring a highly-performant, highly-portable virtual machine to Unity. In January, we shipped our first platform using IL2CPP, . The Unity 5 release brought another platform, . Thanks to the input from our tremendous community of users, we have shipped many patch release
for IL2CPP, steadily improving its compiler and runtime.
We have no plans to stop improving IL2CPP, but we thought it might be a good idea to take a step back and tell you a little bit about how IL2CPP works from the inside out. Over the next few months, we’re planning to write about the following topics (and maybe others) in this IL2CPP Internals series of posts:
The basics – toolchain and command line arguments (this post)
(normal methods, virtual methods, etc.)
In order to make this series of posts possible, we’re going to discuss some details about the IL2CPP implementation that will surely change in the future. Hopefully we can still provide some useful and interesting information.
What is IL2CPP?
The technology that we refer to as IL2CPP has two distinct parts.
An ahead-of-time (AOT) compiler
A runtime library to support the virtual machine
The AOT compiler translates Intermediate Language (IL), the low-level output from .NET compilers, to C++ source code. The runtime library provides services and abstractions like a garbage collector, platform-independent access to threads and files, and implementations of internal calls (native code which modifies managed data structures directly).
The AOT compiler
The IL2CPP AOT compiler is named il2cpp.exe. On Windows you can find it in the Editor\Data\il2cpp directory. On OSX it is in the Contents/Frameworks/il2cpp/build directory in the Unity installation. The il2cpp.exe utility is a managed executable, written entirely in C#. We compile it with both .NET and Mono compilers during our development of IL2CPP.
The il2cpp.exe utility accepts managed assemblies compiled with the Mono compiler that ships with Unity and generates C++ code which we pass on to a platform-specific C++ compiler.
You can think about the IL2CPP toolchain like this:
The runtime library
The other part of the IL2CPP technology is a runtime library to support the virtual machine. We have implemented this library using almost entirely C++ code (it has a little bit of platform-specific assembly code, but let’s keep that between the two of us). We call the runtime library libil2cpp, and it is shipped as a static library linked into the player executable. One of the key benefits of the IL2CPP technology is this simple and portable runtime library.
You can find some clues about how the libil2cpp code is organized by looking at the header files for libil2cpp we ship with Unity (you’ll find them in the
Editor\Data\PlaybackEngines\webglsupport\BuildTools\Libraries\libil2cpp\include directory on Windows, or the Contents/Frameworks/il2cpp/libil2cpp directory on OSX). For example, the interface between the C++ code generated by il2cpp.exe and the libil2cpp runtime is located in the codegen/il2cpp-codegen.h header file.
One key part of the runtime is the garbage collector. We’re shipping Unity 5 with , the Boehm-Demers-Weiser garbage collector. However, libil2cpp has been designed to allow us to use other garbage collectors. For example, we are researching an integration of the Microsoft GC which was open-sourced as part of the CoreCLR. We’ll have more to say about this in our post about garbage collector integration later in the series.
How is il2cpp.exe executed?
Let’s take a look at an example. I’ll be using Unity 5.0.1 on Windows, and I’ll start with a new, empty project. So that we have at least one user script to convert, I’ll add this simple MonoBehaviour component to the Main Camera game object:
[csharp]using UnityE
public class HelloWorld : MonoBehaviour {
void Start () {
Debug.Log(&Hello, IL2CPP!&);
}[/csharp]
When I build for the WebGL platform, I can use
to see the command line Unity used to run il2cpp.exe:
"C:\Program Files\Unity\Editor\Data\MonoBleedingEdge\bin\mono.exe" "C:\Program Files\Unity\Editor\Data\il2cpp/il2cpp.exe" --copy-level=None --enable-generic-sharing --enable-unity-event-support --output-format=Compact --extra-types.file="C:\Program Files\Unity\Editor\Data\il2cpp\il2cpp_default_extra_types.txt" "C:\Users\Josh Peterson\Documents\IL2CPP Blog Example\Temp\StagingArea\Data\Managed\Assembly-CSharp.dll" "C:\Users\Josh Peterson\Documents\IL2CPP Blog Example\Temp\StagingArea\Data\Managed\UnityEngine.UI.dll" "C:\Users\Josh Peterson\Documents\IL2CPP Blog Example\Temp\StagingArea\Data\il2cppOutput"
"C:\Program Files\Unity\Editor\Data\MonoBleedingEdge\bin\mono.exe" "C:\Program Files\Unity\Editor\Data\il2cpp/il2cpp.exe" --copy-level=None --enable-generic-sharing --enable-unity-event-support --output-format=Compact --extra-types.file="C:\Program Files\Unity\Editor\Data\il2cpp\il2cpp_default_extra_types.txt" "C:\Users\Josh Peterson\Documents\IL2CPP Blog Example\Temp\StagingArea\Data\Managed\Assembly-CSharp.dll" "C:\Users\Josh Peterson\Documents\IL2CPP Blog Example\Temp\StagingArea\Data\Managed\UnityEngine.UI.dll" "C:\Users\Josh Peterson\Documents\IL2CPP Blog Example\Temp\StagingArea\Data\il2cppOutput"
That command line is pretty long and horrible, so let’s unpack it. First, Unity is running this executable:
"C:\Program Files\Unity\Editor\Data\MonoBleedingEdge\bin\mono.exe"
"C:\Program Files\Unity\Editor\Data\MonoBleedingEdge\bin\mono.exe"
The next argument on the command line is the il2cpp.exe utility itself.
"C:\Program Files\Unity\Editor\Data\il2cpp/il2cpp.exe"
"C:\Program Files\Unity\Editor\Data\il2cpp/il2cpp.exe"
The remaining command line arguments are passed to il2cpp.exe, not mono.exe. Let’s look at them. First, Unity passes five flags to il2cpp.exe:
–copy-level=None
Specify that il2cpp.exe should not perform an special file copies of the generated C++ code.
–enable-generic-sharing
This is a code and binary size reduction feature. IL2CPP will share the implementation of generic methods when it can.
–enable-unity-event-support
Special support to ensure that code for Unity events, which are accessed via reflection, is correctly generated.
–output-format=Compact
Generate C++ code in a format that requires fewer characters for type and method names. This code is difficult to debug, since the names in the IL code are not preserved, but it often compiles faster, since there is less code for the C++ compiler to parse.
–extra-types.file=”C:\Program Files\Unity\Editor\Data\il2cpp\il2cpp_default_extra_types.txt”
Use the default (and empty) extra types file. This file can be added in a Unity project to let il2cpp.exe know which generic or array types will be created at runtime, but are not present in the IL code.
It is important to note that these command line arguments can and will be changed in later releases. We’re not at a point yet where we have a stable and supported set of command line arguments for il2cpp.exe.
Finally, we have a list of two files and one directory on the command line:
“C:\Users\Josh Peterson\Documents\IL2CPP Blog Example\Temp\StagingArea\Data\Managed\Assembly-CSharp.dll”
“C:\Users\Josh Peterson\Documents\IL2CPP Blog Example\Temp\StagingArea\Data\Managed\UnityEngine.UI.dll”
“C:\Users\Josh Peterson\Documents\IL2CPP Blog Example\Temp\StagingArea\Data\il2cppOutput”
The il2cpp.exe utility accepts a list of all of the IL assemblies it should convert. In this case they are the assembly containing my simple MonoBehaviour, Assembly-CSharp.dll, and the GUI assembly, UnityEngine.UI.dll. Note that there are a few conspicuously missing assembles here. Clearly, my script references UnityEngine.dll, and that references at least mscorlib.dll, and maybe other assemblies. Where are they? Actually, il2cpp.exe resolves those assemblies internally. They can be mentioned on the command line, but they are not necessary. Unity only needs to mention the root assemblies (those which are not referenced by any other assembly) explicitly.
The last argument on the il2cpp.exe command line is the directory where the output C++ files should be created. If you are curious, have a look at the generated files in that directory, they will be the subject of the next post in this series. Before you do though, you might want to choose the “Development Player” option in the WebGL build settings. That will remove the –output-format=Compact command line argument and give you better type and method names in the generated C++ code.
Try changing various options in the WebGL or iOS Player Settings. You should be able to see different command line options passed to il2cpp.exe to enable different code generation steps. For example, changing the “Enable Exceptions” setting in the WebGL Player Settings to a value of “Full” adds the –emit-null-checks, –enable-stacktrace, and
–enable-array-bounds-check arguments to the il2cpp.exe command line.
What does IL2CPP not do?
I’d like to point out one of the challenges that we did not take on with IL2CPP, and we could not be happier that we ignored it. We did not attempt to re-write the C# standard library with IL2CPP. When you build a Unity project which uses the IL2CPP scripting backend, all of the C# standard library code in mscorlib.dll, System.dll, etc. is the exact same code used for the Mono scripting backend.
We rely on C# standard library code that is already well-known by users and well-tested in Unity projects. So when we investigate a bug related to IL2CPP, we can be fairly confident that the bug is in either the AOT compiler or the runtime library, and nowhere else.
How we develop, test, and ship IL2CPP
Since the initial public release of IL2CPP at version 4.6.1p5 in January, we’ve shipped 6 full releases and 7 patch releases (across versions 4.6 and 5.0 of Unity). We have corrected more than 100 bugs mentioned in the release notes.
In order to make this continuous improvement happen, we develop against only one version of the IL2CPP code internally, which sits on the bleeding edge of the trunk branch in Unity used to ship alpha and beta releases. Just before each release, we port the IL2CPP changes to the specific release branch, run our tests, and verify all of the bugs we fixed are corrected in that version. Our QA and Sustained Engineering teams have done incredible work to make delivery at this rate possible. This means that our users are never more than about one week away from the latest fixes for IL2CPP bugs.
Our user community has proven invaluable by submitting many high quality bug reports. We appreciate all the feedback from our users to help continually improve IL2CPP, and we look forward to more of it.
The development team working on IL2CPP has a strong test-first mentality. We often employee Test Driven Design practices, and seldom merge a pull request without good tests. This strategy works well for a technology like IL2CPP, where we have clear inputs and outputs. It means that the vast majority of the bugs we see are not unexpected behavior, but rather unexpected cases (e.g. it is possible to use an 64-bit IntPtr as a 32-bit array index, causing clang to fail with a C++ compiler error, and
actually does this!). That difference allows us to fix bugs quickly with a high degree of confidence.
With the help of our community, we’re working hard to make IL2CPP as stable and fast as possible. By the way, if any of this excites you,
(just sayin’).
More to come
I fear that I’ve spent too much time here teasing future blog posts. We have a lot to say, and it simply won’t all fit in one post. Next time, we’ll dig into the code generated by il2cpp.exe to see how your project actually looks to the C++ compiler.
Related posts
, July 26, 2016
, April 1, 2016
, December 23, 2015
, July 20, 2015
Categories
Subscribe to all posts
Subscribe to Asset Store
Subscribe to Case Study
Subscribe to Community
Subscribe to Events
Subscribe to Rants & Raves
Subscribe to Services
Subscribe to Technology
Subscribe to Unity Ads
Subscribe to Unity Analytics
Popular posts
Quick links
About Unity
Get Unity news
I agree to the
and the processing and use of my information
Nearly there...
To start receiving news from Unity Technologies, click on the link we've sent to your e-mail account.
Something went wrong, please try again.
Copyright & 2016 Unity Technologiesunity(145)
http://inpla.net/thread-.html
Unity3D将来时:IL2CPP(上)
(注:本文详细的讲述了C#,Mono,.Net, IL等Unity使用到的概念,如果你已经熟知这些,可以直接跳过看下篇)
Unity3D想必大家都不陌生,独立游戏制作者们很多人都在用它,甚至一些大公司也用在很商业的游戏制作上。Unity3D最大的一个特点是一次制作,多平台部署,而这一核心功能是靠Mono实现的。可以说Mono是Unity3D核心的核心,是Unity3D跨平台的根本。但是在2014年年中的时候,Unity3D官方博客上却发了一篇“”的文章,引出了IL2CPP的概念,感觉有取代Mono之势。那什么是IL2CPP,它能为Unity3D和作为使用Unity3D的我们带来哪些好处和改变?这就是本文尝试说明的。
C#,.Net Framework
我们先说说IL2CPP试图取代的Mono。在说Mono之前,不得不提C#语言和背后的.Net Framework。C#是微软推出的一种基于.NET框架的、面向对象的高级编程语言。C#的发音为“see sharp”,模仿音乐上的音名“C?”(C调升),是C语言的升级的意思。其正确写法应和音名一样为“C?”。C#由C语言和C++派生而来,继承了其强大的性能,同时又以.NET框架类库作为基础,拥有类似Visual Basic的快速开发能力。C#由安德斯·海尔斯伯格主持开发,微软在2000年发布了这种语言。说到安德斯·海尔斯伯格这里要多说一句,当年和VC(注意,是VC,那个时候还没有Virtual
Studio)齐名还有另外一家公司的IDE也非常流行,那就是Borland公司的Delphi,也是由安德斯·海尔斯伯格主导开发的。
他后来被微软挖走,创建了J++,一门类似Java的语言(好吧,以我肤浅的知识认为,那基本就是照着Java做的)。后来由于和Sun公司授权的原因,微软在2001年停止了J++的开发而推出了C# 1.0。说来要感谢和Sun的这场官司,否则微软也不会有C#,J++也可能一直会跟随Java的脚步。相反C#经过不断的进化,从1.0开始到4.0和最新的5.0,C#已经远远甩开Java几条街了(还是以我个人的使用Java和C#感觉而言,关于两门语言的比较,无论是效率上,夸平台上,还是语言易用性上,社区活跃度上,网上的争论随处可见,每个人都有自己的看法,这也不是本文的重点)。
Mono,Mono VM
C#虽好,但是只能在Windows上运行,微软那时候也没有将其开源,所以总是会有人说不能跨平台,光就这点,C#和Java就不能比呀。
微软公司已经向ECMA申请将C#作为一种标准。在2001年12月,ECMA发布了ECMA-334 C#语言规范。C#在2003年成为一个ISO标准(ISO/IEC 23270)。这意味着只要你遵守CLI(Common Language Infrastructure),第三方可以将任何一种语言实现到.Net平台之上。Mono就是在这种环境下诞生的。
Mono是一个由Xamarin公司(先前是Novell,最早为Ximian)所主持的自由开放源代码项目。该项目的目标是创建一系列符合ECMA标准(Ecma-334和Ecma-335)的.NET工具,包括C#编译器和通用语言架构。与微软的.NET Framework(共通语言运行平台)不同,Mono项目不仅可以运行于Windows系统上,还可以运行于Linux,FreeBSD,Unix,OS X和Solaris,甚至一些游戏平台,例如:Playstation 3,Wii或XBox 360之上。Mono使得C#这门语言有了很好的跨平台能力。相对于微软的.Net
Framework运行时库Mono使用自己的Mono VM作为运行时库。 加上C#本身快速友好的开发能力,最终使得Unity团队在创建之初就决定将Mono,C#作为其核心。(嗯,这是我猜的)
有人也许会说,Unity还支持JavaScript和Boo呢,不光光只有C#一门语言。首先我要纠正的是,在Unity中的JavaScript严格意义上说并不是W3C规范中的JavaScript,它正确的名字叫做Unity Script,其实是从Boo演变过来的(这样大家就能理解为啥在3门语言中,Boo用的人最少,但是却还一直存在的原因了吧)。我认为是Unity开始为了让更多的人能够快速的上手,特别是考虑到很多脚本程序员对JavaScript已经很熟悉了,为了照顾这部分人,发明了Unity Script,它的语法和W3C的JavaScript几乎一致,使得大家可以直接用其进行开发,降低门槛。但是Unity
Script在运行上却和JavaScript有着本质的不同。这个我会在下一节IL中进行详细的描述。从三门语言在Unity中的使用情况而言:Boo几乎就没人用了,Unity Script和C#两者中无论是演示代码还是Unity Asset Store中的第三方代码,C#已经有85%-90%的比例(个人粗略估计,没有做详细统计)。可见C#在Unity中深受我等游戏码农的爱戴。
啰嗦完了C#,.Net Framework和Mono,引出了我们很重要的一个概念”IL“。IL的全称是 Intermediate Language,很多时候还会看到CIL(Common Intermediate Language,特指在.Net平台下的IL标准)。在Unity博客和本文中,IL和CIL表示的是同一个东西:翻译过来就是中间语言。它是一种属于通用语言架构和.NET框架的低阶(lowest-level)的人类可读的编程语言。目标为.NET框架的语言被编译成CIL,然后汇编成字节码。CIL类似一个面向对象的汇编语言,并且它是完全基于堆栈的,它运行在虚拟机上(.Net
Framework, Mono VM)的语言。
具体过程是:C#或者VB这样遵循CLI规范的高级语言,被先被各自的编译器编译成中间语言:IL(CIL),等到需要真正执行的时候,这些IL会被加载到运行时库,也就是VM中,由VM动态的编译成汇编代码(JIT)然后在执行。
正是由于引入了VM,才使得很多动态代码特性得以实现。通过VM我们甚至可以由代码在运行时生成新代码并执行。这个是静态编译语言所无法做到的。回到上一节我说的Boo和Unity Script,有了IL和VM的概念我们就不难发现,这两者并没有对应的VM虚拟机,Unity中VM只有一个:Mono VM,也就是说Boo和Unity Script是被各自的编译器编译成遵循CLI规范的IL,然后再由Mono VM解释执行的。这也是Unity Script和JavaScript的根本区别。JavaScript是最终在浏览器的JS解析器中运行的(例如大名鼎鼎的Google
Chrome V8引擎),而Unity Script是在Mono VM中运行的。本质上说,到了IL这一层级,它是由哪门高级语言创建的也不是那么重要了,你可以用C#,VB,Boo,Unity Script甚至C++,只要有相应的编译器能够将其编译成IL都行!
IL2CPP, IL2CPP VM
本文的”男猪脚“终于出来了:IL2CPP。有了上面的知识,大家很容易就理解其意义了:把IL中间语言转换成CPP文件。大家如果看明白了上面动态语言的CLI, IL以及VM,再看到IL2CPP一定心中充满了疑惑。现在的大趋势都是把语言加上动态特性,哪怕是c++这样的静态语言,也出现了适合IL的c++编译器,为啥Unity要反其道而行之,把IL再弄回静态的CPP呢?这不是吃饱了撑着嘛。根据本文最前面给出的Unity官方博客所解释的,原因有以下几个:
1.Mono VM在各个平台移植,维护非常耗时,有时甚至不可能完成
& && &&&Mono的跨平台是通过Mono VM实现的,有几个平台,就要实现几个VM,像Unity这样支持多平台的引擎,Mono官方的VM肯定是不能满足需求的。所以针对不同的新平台,Unity的项目组就要把VM给移植一遍,同时解决VM里面发现的bug。这非常耗时耗力。这些能移植的平台还好说,还有比如WebGL这样基于浏览器的平台。要让WebGL支持Mono的VM几乎是不可能的。
2.Mono版本授权受限
& && &&&大家有没有意识到Mono的版本已经更新到3.X了,但是在Unity中,C#的运行时版本一直停留在2.8,这也是Unity社区开发者抱怨的最多一条:很多C#的新特性无法使用。这是因为Mono 授权受限,导致Unity无法升级Mono。如果换做是IL2CPP,IL2CPP VM这套完全自己开发的组件,就解决了这个问题。
3.提高运行效率
& && &&&根据官方的实验数据,换成IL2CPP以后,程序的运行效率有了1.5-2.0倍的提升。
使用Mono的时候,脚本的编译运行如下图所示:
简单的来说,3大脚本被编译成IL,在游戏运行的时候,IL和项目里其他第三方兼容的DLL一起,放入Mono VM虚拟机,由虚拟机解析成机器码,并且执行
IL2CPP做的改变由下图红色部分标明:
在得到中间语言IL后,使用IL2CPP将他们重新变回C++代码,然后再由各个平台的C++编译器直接编译成能执行的原生汇编代码。
几点注意:
1.将IL变回CPP的目的除了CPP的执行效率快以外,另一个很重要的原因是可以利用现成的在各个平台的C++编译器对代码执行编译期优化,这样可以进一步减小最终游戏的尺寸并提高游戏运行速度。
2.由于动态语言的特性,他们多半无需程序员太多关心内存管理,所有的内存分配和回收都由一个叫做GC(Garbage Collector)的组件完成。虽然通过IL2CPP以后代码变成了静态的C++,但是内存管理这块还是遵循C#的方式,这也是为什么最后还要有一个IL2CPP VM的原因:它负责提供诸如GC管理,线程创建这类的服务性工作。但是由于去除了IL加载和动态解析的工作,使得IL2CPP VM可以做的很小,并且使得游戏载入时间缩短。
3.由于C++是一门静态语言,这就意味着我们不能使用动态语言的那些酷炫特性。运行时生成代码并执行肯定是不可能了。这就是Unity里面提到的所谓AOT(Ahead Of Time)编译而非JIT(Just In Time)编译。其实很多平台出于安全的考虑是不允许JIT的,大家最熟悉的有iOS平台,在Console游戏机上,不管是微软的Xbox360, XboxOne,还是Sony的PS3,PS4,PSV,没有一个是允许JIT的。使用了IL2CPP,就完全是AOT方式了,如果原来使用了动态特性的代码肯定会编译失败。这些代码在编译iOS平台的时候天生也会失败,所以如果你是为iOS开发的游戏代码,就不用担心了。因此就这点而言,我们开发上几乎不会感到什么问题。
最后给出Unite 2014上官方给出的性能测试截图(数字越小表示运行得越快):
有了IL2CPP,程序尺寸可以相对缩小,运行速度可以提高!看了兴奋吗?其实现有的Unity版本中已经引入了IL2CPP技术。本文下篇就通过一个实际的例子,看看IL2CPP都为我们做了哪些,以及我们需要注意些什么。
参考链接:
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:300844次
积分:4792
积分:4792
排名:第3999名
原创:123篇
转载:365篇
评论:67条
(2)(47)(4)(9)(41)(21)(19)(8)(9)(15)(19)(4)(4)(3)(8)(16)(22)(24)(6)(8)(15)(15)(10)(9)(15)(15)(5)(11)(10)(1)(27)(17)(2)(2)(4)(2)(9)(1)(1)(2)(3)(3)(23)(9)}

我要回帖

更多关于 unity3d il2cpp 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信