Unity 2017.3b功能预览:程序集定义文件和转换工具
As the release of Unity 2017.3 is drawing near, we’d like to show you two nifty features that you might like.
随着Unity 2017.3版本的临近,我们想向您展示您可能喜欢的两个漂亮功能。
The first feature is Assembly Definition Files. With this feature, you’ll get the option to define your own managed assemblies inside a folder. With well-defined dependencies you’ll ensure that only the required assemblies will be rebuilt, when you make a change in a script, reducing compilation time.
第一个功能是程序集定义文件。 使用此功能,您将可以选择在文件夹内定义自己的托管程序集。 使用定义明确的依赖项,您可以确保在脚本中进行更改时仅重建所需的程序集,从而减少了编译时间。
The larger your project grows, the greater the compilation time will inevitably end up being. When iterating on a project this can easily become a nuisance, so setting up proper assembly definition files should help you work more efficiently and waste less time waiting for scripts to compile.
您的项目规模越大,编译时间就不可避免地越长。 在项目上进行迭代时,这很容易成为麻烦,因此设置适当的程序集定义文件应有助于您更有效地工作,并减少等待脚本编译的时间。
The second feature is the new Transform Tool. The Transform Tool is a mix of the three current tools; Move, Rotate and Scale suitable for those situations, where easy access to all three is required. A small thing, but also a potential time saver.
第二个功能是新的转换工具。 转换工具是三个当前工具的组合。 移动,旋转和缩放适用于需要轻松访问这三个位置的情况。 小事情,但也可能节省时间。
You can test out the above features (and more) right now while waiting for the full release of Unity 2017.3, by simply downloading the 2017.3 beta here. Remember to take backups before upgrading your project.
您可以在等待Unity 2017.3完整版的同时立即测试上述功能(以及更多功能),只需 在此处下载2017.3 beta 。 在升级项目之前,请记住进行备份。
脚本编译–程序集定义文件 (Script Compilation – Assembly Definition Files)
Unity automatically defines how scripts compile to managed assemblies. Typically, compilation times in the Unity Editor for iterative script changes increase as you add more scripts to the Project. When you are going through an iterative process you want the builds to compile as fast and smooth as possible.
Unity自动定义脚本如何编译为托管程序集。 通常, 随着您向 项目中 添加更多脚本,Unity编辑器中用于迭代脚本更改的 编译 时间会增加 。 在进行迭代过程时,您希望构建尽可能快且平稳地进行编译。
You can use an assembly definition file to define your own managed assemblies based upon scripts inside a folder. If you separate Project scripts into multiple assemblies with well-defined dependencies, you’ll ensure that only required assemblies are rebuilt when making changes in a script. This reduces compilation times, so you can think of each managed assembly as a single library within the Unity Project.
您可以使用程序集定义文件根据文件夹内的脚本定义自己的托管程序集。 如果将Project脚本分成具有明确定义的 依赖关系的 多个程序集,则将 确保 在脚本中 进行 更改 时仅重建所需的程序集 。 这减少了编译时间,因此您可以将每个托管程序集视为Unity项目中的单个库。
The figure above illustrates how you can split the Project scripts into several assemblies. If you are only changing scripts in Main.dll, none of the other assemblies will need to recompile. Since Main.dll contains fewer scripts, it also compiles faster than Assembly-CSharp.dll.
上图说明了如何将Project脚本拆分为几个程序集。 如果仅在Main.dll中更改脚本,则其他任何程序集都不需要重新编译。 由于Main.dll包含的脚本较少,因此它的编译速度也比Assembly-CSharp.dll快。
Similarly, script changes you make in Stuff.dll will only cause Main.dll and Stuff.dll to recompile.
同样,您在Stuff.dll中进行的脚本更改只会导致Main.dll和Stuff.dll重新编译。
如何使用程序集定义文件 (How to use assembly definition files)
Assembly definition files are Asset files that you create by going to Assets > Create > Assembly Definition. They have the extension .asmdef .
程序集定义文件是您通过转到资产 > 创建 > 程序集定义 创建的资产文件 。 它们具有扩展名 .asmdef。
You can add an assembly definition file to a folder in a Unity Project to compile all the scripts in the folder into an assembly, and then set the name of the assembly in the Inspector.
您可以将程序集定义文件添加到Unity项目中的文件夹中,以将该文件夹中的所有脚本编译为程序集,然后在检查器中设置程序集的名称。
Note: The name of the folder in which the assembly definition file resides and the filename of the assembly definition file have no effect on the name of the assembly.
注意: 程序集定义文件所在的文件夹的名称和程序集定义文件的文件名对 程序集的名称无效。
Add references to other assembly definition files in the Project using the Inspector too. The references are used when compiling the assemblies and define the dependencies between the assemblies.
也可以使用检查器在项目中添加对其他程序集定义文件的引用。 编译程序集时使用引用,并定义 程序集 之间 的 依赖关系 。
Unity uses the references to compile the assemblies and also defines the dependencies between the assemblies.
Unity使用引用来编译程序集,并定义 程序集之间的 依赖 关系。
You can set the platform compatibility for the assembly definition files in the Inspector. You have the option to exclude or include specific platforms.
您可以在检查器中为程序集定义文件设置平台兼容性。 您可以选择排除或包括特定平台。
文件夹层次结构中的多个程序集定义文件 (Multiple assembly definition files inside a folder hierarchy)
If you have multiple assembly definition files (extension: .asmdef) inside a folder hierarchy it will cause each script to be added to the assembly definition file with the shortest path distance.
如果您在文件夹层次结构中有多个程序集定义文件(扩展名:.asmdef),它将导致每个脚本以最短的路径距离添加到程序集定义文件中。
Example:
例:
If you have a Assets/ExampleFolder/MyLibrary.asmdef and a Assets/ExampleFolder/ExampleFolder2/Utility.asmdef file, then:
如果您有一个Assets / ExampleFolder / MyLibrary.asmdef和一个 Assets / ExampleFolder / ExampleFolder2 / Utility.asmdef文件,则:
-
Any scripts inside the Assets > ExampleFolder > ExampleFolder2 folder will be compiled into the Assets/ExampleFolder/ExampleFolder2/Utility.asmdef defined assembly.
Assets > ExampleFolder > ExampleFolder2文件夹内的所有脚本都将编译到Assets / ExampleFolder / ExampleFolder2 / Utility.asmdef定义的程序集中。
-
Any files in the Assets > ExampleFolder folder that are not inside Assets > ExampleFolder > ExampleFolder2 folder would be compiled into the Assets/ExampleFolder/MyLibrary.asmdef defined assembly.
资产 > ExampleFolder文件夹中不在资产 > ExampleFolder > ExampleFolder2文件夹内的所有文件都将被编译到Assets / ExampleFolder / MyLibrary.asmdef定义的程序集中。
程序集定义文件不是构建系统文件 (Assembly definition files are not build system files)
**Note** : The assembly definition files are not assembly build files. They do not support conditional build rules typically found in build systems.
**注意** :程序集定义文件不是程序集构建文件。 它们不支持 通常在构建系统中发现的条件构建规则。
This is also the reason why the assembly definition files do not support setting of preprocessor directives (defines), as those are static at all times.
这也是程序集定义文件不支持 预处理程序指令(定义) 设置的原因 ,因为它们始终是静态的。
向后兼容和隐式依赖 (Backwards compatibility and implicit dependencies)
Assembly definition files are backwards compatible with the existing Predefined Compilation System in Unity. This means that the predefined assemblies always depend on every assembly definition file’s assemblies. This is similar to how all scripts are dependent on all precompiled assemblies (plugins / .dlls) compatible with the active build target in Unity.
程序集定义文件与 Unity中 现有的预定义编译系统向后兼容 。 这意味着预定义程序集始终依赖于每个程序集定义文件的程序集。 这类似于所有脚本如何依赖 与Unity中活动构建目标兼容的 所有预编译程序集(插件/ .dlls)的方式 。
The diagram in Figure 3 illustrates the dependencies between predefined assemblies, assembly definition files assemblies and precompiled assemblies.
图3中的图说明了预定义程序集,程序集 定义文件程序集和预编译程序集 之间的依赖关系 。
Unity gives priority to the assembly definition files over the Predefined Compilation System.
Unity优先于程序集定义文件,而不是预定义编译系统 。
This means that having any of the special folder names from the predefined compilation inside an assembly definition file folder will not have any effect on the compilation. Unity treats these as regular folders without any special meaning.
这意味着在 程序集定义文件文件夹中 包含预定义编译中的任何特殊文件夹名称 都不会对编译产生任何影响。 Unity将它们 视为常规文件夹,没有任何特殊含义。
It is highly recommended that you use assembly definition files for all the scripts in the Project, or not at all. Otherwise, the scripts that are not using assembly definition files always recompile every time an assembly definition file recompiles. This reduces the benefit of using assembly definition files in your project.
强烈建议您对项目中的所有脚本都使用程序集定义文件, 或者根本不使用。 否则, 每次 重新使用程序集定义文件时,不使用程序集定义文件的脚本将始终重新 编译。 这降低了 在项目 中使用程序集 定义文件 的好处 。
API (API)
In the namespace UnityEditor.Compilation there is a static CompilationPipeline class that you use to retrieve information about assembly definition files and all assemblies built by Unity.
在名称空间UnityEditor.Compilation中,有一个静态CompilationPipeline类, 可用于检索有关程序集定义文件和Unity生成的所有程序集的信息。
文件格式 (File Format)
Assembly definition files are JSON files. They have the following fields:
程序集定义文件是JSON文件。 它们具有以下字段:
Field | Type |
name | string |
references (optional) | string array |
includePlatforms (optional) | string array |
excludePlatforms (optional) | string array |
领域 | 类型 |
名称 | 串 |
参考 (可选) | 字符串数组 |
includePlatforms (可选) | 字符串数组 |
excludePlatforms (可选) | 字符串数组 |
The fields includePlatforms and excludePlatforms cannot be used together in the same assembly definition file.
字段includePlatforms和excludePlatforms不能在 同一个组件定义文件 一起使用在一起 。
Retrieve the platform names by using
使用检索平台名称
1
|
CompilationPipeline.GetAssemblyDefinitionPlatforms
|
1
|
CompilationPipeline . GetAssemblyDefinitionPlatforms
|
例子 (Examples)
1
2
3
4
5
6
|
MyLibrary.asmdef
{
"name" : "MyLibrary" ,
"references" : [ "Utility" ],
"includePlatforms" : [ "Android" , "iOS" ]
}
|
1
2
3
4
5
6
|
MyLibrary . asmdef
{
"name" : "MyLibrary" ,
"references" : [ "Utility" ] ,
"includePlatforms" : [ "Android" , "iOS" ]
}
|
1
2
3
4
5
6
|
MyLibrary2.asmdef
{
"name" : "MyLibrary2" ,
"references" : [ "Utility" ],
"excludePlatforms" : [ "WebGL" ]
}
|
1
2
3
4
5
6
|
MyLibrary2 . asmdef
{
"name" : "MyLibrary2" ,
"references" : [ "Utility" ] ,
"excludePlatforms" : [ "WebGL" ]
}
|
You can find the Assembly Definition Files Example Project on our forum, and download the 2017.3 beta here.
您可以 在我们的论坛上 找到 Assembly Definition Files Example Project ,并 在此处下载2017.3 beta 。
转换工具 (Transform Tool)
One of the other useful features you’ll find in the 2017.3 beta is the new Transform Tool. The Transform Tool is a multitool that contains the functionality of the standard three Move, Rotate and Scale tools. The Transform Tool isn’t meant to replace the three standard tools, but to provide a tool for situations where you would want all of the present without having to switch back and forth between them.
您可以在2017.3 Beta中找到的其他有用功能之一是新的“转换工具”。 变换工具是一个多功能工具,包含标准的三个“移动”,“旋转”和“缩放”工具的功能。 转换工具并不是要取代这三个标准工具,而是提供一种工具,用于您需要所有现有信息而不必在它们之间来回切换的情况。
To get early access and try out the new Transform Tool coming soon in 2017.3, you can download the Unity 2017.3 beta. Once installed, you’ll have access to this and all of the upcoming features in the next version of Unity.
要抢先体验并尝试2017.3即将推出的新转换工具,您可以 下载Unity 2017.3 beta。 安装后,您将可以在下一版本的Unity中访问此功能以及所有即将推出的功能。
启用转换工具 (Enabling the Transform Tool)
To begin using the Transform Tool, click the Transform Tool button in the toolbar or press “Y”.
要开始使用“变换工具”,请单击工具栏中的“变换工具”按钮或按“ Y”。
You’ll now have access to the Transform Tool gizmo.
现在,您可以访问“变换工具”小控件。
World gizmo
世界小发明
With the pivot rotation set to “Global” mode, you can translate and rotate the GameObject along the global axes.
将枢轴旋转设置为“全局”模式后,您可以沿全局轴平移和旋转GameObject。
Axis translation, Plane translation
轴平移,平面平移
Axis rotation, Screen Space rotation, Free rotation
轴旋转,屏幕空间旋转,自由旋转
Global scaling
全局扩展
Local gizmo
本地小发明
When the pivot rotation is in “Local” mode, you can also scale along local axes.
当枢轴旋转处于“本地”模式时,您也可以沿本地轴缩放。
Local axis scaling
局部轴缩放
屏幕空间Gizmo (Screen Space Gizmo)
If you keep the “SHIFT” key pressed, the gizmo enters Screen Space mode. In this mode, you can translate and rotate in screen space.
如果按住“ SHIFT”键,则小控件将进入“屏幕空间”模式。 在此模式下,您可以在屏幕空间中平移和旋转。
Axis translation, Plane translation, Axis rotation and Global scaling
轴平移,平面平移,轴旋转和全局缩放
抓拍 (Snapping)
When you keep the “CTRL” (Win) or “Command” (OSX) key pressed, the unit snapping is activated for:
按住“ CTRL”(Win)或“ Command”(OSX)键时,将**以下单元锁定:
-
Axes translations
轴翻译
-
Plane translations
平面翻译
-
Axes rotations
轴旋转
-
Axes scaling
轴缩放
-
Global scaling
全局扩展
Plane translation, Axis translation, Global scaling, Axis rotation
平面平移,轴平移,全局缩放,轴旋转
顶点捕捉 (Vertex Snapping)
When you press and keep the “V” key pressed, the gizmos enters vertex snapping mode. This way, you can translate your gameobject so one of its vertex is placed on the vertex of another object.
当您按下并按住“ V”键时,小控件将进入顶点捕捉模式。 这样,您可以平移游戏对象,以便将其一个顶点放置在另一个对象的顶点上。
Plane translation, Axis translation, Global scaling, Axis rotation
平面平移,轴平移,全局缩放,轴旋转
立即抢先使用功能 (Get early access to the features now)
Both Assembly Definition Files and the Transform Tool are a part of the Unity 2017.3 beta together with new improvements to the particle system, an updated Crunch texture compression library and much more. Test compatibility with your current project or play around with the new features by downloading the beta. You also still have time to be a part of this round of beta sweepstakes too for the chance of winning one of three Acer Windows Mixed Reality headsets with Motion Controllers, sponsored by our friends at Microsoft – read more about that here.
装配体定义文件和变换工具都是Unity 2017.3 Beta的一部分, 并对粒子系统进行了新改进 ,还提供了更新的 Crunch纹理压缩库 等。 通过 下载Beta 测试与当前项目的兼容性,或使用新功能 。 您也仍有时间参与本轮Beta抽奖活动,有机会赢得由Microsoft朋友赞助的三台带有运动控制器的Acer Windows Mixed Reality头戴式耳机之一- 在此处 了解更多信息 。