英文:
How does Unity makes C# compileable to Android?
问题
Android的本地语言是Java,Unity使用C#,但仍然有选项可以编译为Android。Godot也使用GDScript,Godot的源代码是C++,但他们仍然能够使用一些我不了解的机制编译为Android。它是如何实现跨平台的,是否有关于这方面的教程?
英文:
The native language of Android is Java, and Unity uses C#, but there is still option to compile to Android. Godot also uses GDScript and source code of Godot is C++, but they still able to compile to Android with some unknown to me mechanics. How does it crossplatform like that and is there any tutorials for this?
答案1
得分: 1
以下是您要翻译的内容:
有3个脚本后端(截至本答案发布时):
- Mono2x 标准的Mono 2.6运行时。
- IL2CPP Unity的.NET运行时。
- WinRTDotNET Microsoft的.NET运行时。
IL2CPP
Unity的脚本后端IL2CPP(Intermediate Language To C++)使用AOT编译并支持许多目标。并非所有目标都支持AOT(提前编译)。
IL2CPP后端将MSIL(Microsoft中间语言)代码(例如脚本中的C#代码)转换为C++代码,然后使用C++代码创建所选平台的本机二进制文件(例如.exe、.apk或.xap)。
您可以在这里阅读更多信息IL2CPP后端。
它所采取的步骤(摘自上述链接)包括:
- Roslyn C#编译器编译您的应用程序的C#代码和任何所需的包代码为.NET DLLs(托管程序集)。
- Unity应用托管字节码剥离。此步骤可以显著减小构建应用程序的大小。
- IL2CPP后端将所有托管程序集转换为标准C++代码。
- C++编译器使用本机平台编译器编译生成的C++代码和IL2CPP的运行时部分。
- Unity创建可执行文件或DLL,具体取决于您的目标平台。
Mono
Mono脚本后端使用JIT编译。并非所有平台都支持JIT(即时)编译。Unity的文档提供了较少的信息,但我认为您可以从Mono文档中获得完整的详细信息。
您可以在这里阅读更多信息Mono后端。
如果两种脚本后端都受支持,Mono是默认选择。
由于添加了WinRTDotNET,不确定是否仍然是这种情况,但我会这么假设。
WinRTDotNET
目前在Unity的脚本后端文档中没有关于WinRTDotNET的信息。这是脚本后端的最新添加。关于IL2CPP中的Windows实时支持的一些信息可以在这里找到IL2CPP Windows Runtime Support。
英文:
There are 3 Scripting Backends (at the time of this answer).
- Mono2x The standard Mono 2.6 runtime.
- IL2CPP Unity's .NET runtime.
- WinRTDotNET Microsoft's .NET runtime.
IL2CPP
Unity's scripting backend IL2CPP (Intermediate Language To C++) uses AOT compilation and supports many targets. Not all targets support AOT (ahead of time) compilation.
>The IL2CPP backend converts MSIL (Microsoft Intermediate Language) code (for example, C# code in scripts) into C++ code, then uses the C++ code to create a native binary file (for example, .exe, .apk, or .xap) for your chosen platform.
You can read more about this here IL2CPP Backend.
The steps it takes (taken from the above link) are:
> 1. The Roslyn C# compiler compiles your application’s C# code and any required package code to .NET DLLs (managed assemblies).
> 2. Unity applies managed bytecode stripping. This step can significantly reduce the size of a built application.
> 3. The IL2CPP backend converts all managed assemblies into standard C++ code.
> 4. The C++ compiler compiles the generated C++ code and the runtime part of IL2CPP with a native platform compiler.
> 5. Unity creates either an executable file or a DLL, depending on the platform you target.
Mono
The Mono scripting backend uses JIT compilation. Not all platforms support JIT (Just In Time) compilation. Less information is provided in unitys documentation, though I suspect you can get the full details from the Mono documentation.
You can read more about this here Mono Backend
If both scripting backends are supported, Mono is the default.
Not sure if this is still the case, with the addition of WinRTDotNET, but I would assume so.
WinRTDotNET
There is no information currently in unitys scripting backend documentation regarding WinRTDotNET. This is the newest addition to the scripting backends. Some information for Windows Realtime Support in IL2CPP can be found here IL2CPP Windows Runtime Support
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论