介绍

Unity 2018.3 是一个重大更新的版本,终于增加了这么多年缺失的嵌套 Prefab 功能,使工作流变得更顺畅。

本文将此次更新中的重点列出来并点评,来源包括官方博客介绍、发布日志、升级向导以及未在文档中提到的内容。

更新日志

Unity 2018.3 介绍

Unity 2018.3 发布日志

What’s new in Unity 2018.3 - Unity

Unity 2018.3 升级向导

Unity - Manual: Upgrading to Unity 2018.3

重点功能

编辑器和工作流程

预制件嵌套功能和改进的预制件工作流程

Unity收到用户反馈中最重要的一项功能就是预制件嵌套功能。根据150多家企业开发者的调查、大量访谈、数次可用性测试以及二次Game Jam活动(均有多家独立工作室和3A工作室参加)获得的信息,了解到不少开发者希望我们对预制件工作流程进行改进 。因此,我们针对可重用性、可控性和安全性,对整个预制件系统进行了改进。该版本的长期计划不仅是实现嵌套支持,还要重新构思核心预制件工作流程,从而使不同团队成员可以同时高效地编辑预制件。

Prefab 的更新才是最近几年更新中最重要的功能,它完全革新了资源的制作方式,终于可以根据需要完全复用以前的东西。

用户偏好设置窗口

Unity 2018.3加入了全新的设置窗口,以提供稳定高效的方法来查找并管理所有用户偏好和项目设置。该窗口可以停靠在编辑器中,拥有简单的左右双栏导航布局,你可以通过搜索功能来快速找到需要调整的设置。

引擎更新

物理功能

PhysX 3.4

Unity 2018.2将NVIDIA PhysX的版本从3.3升级到3.4。此次更新使多项操作的速度比以前快一倍,例如:光线投射,形状扫描和网格烘焙。新版本还改进对快速旋转对象的碰撞检测支持,加入了强化的结果输出,当所有输入内容一致时,PhysX能产生相同结果。

我们在C# Job System扩展了PhysX提供的功能。这样能允许你在主线程外异步使用大部分碰撞体类型,从而在多核硬件上显著提高性能。PhysX 3.4还加入了大量改进,以提高稳定性和性能。PhysX 3.4现在支持多世界和C# Job查询。

垃圾回收控制

Unity 2018.3加入了全新的UnityEngine.Scripting.GarbageCollector脚本API,用于在全局启用和禁用Mono和IL2CPP脚本后端的运行时垃圾回收功能。如果你小心管理内存,在运行时有很少或几乎没有内存分配,你可以通过禁用来避免垃圾回收器的性能开销。当你能承担起性能开销时,可以启用垃圾回收器,并调用System.GC.Collect()来强制进行垃圾回收。换句话说,垃圾回收过程不会随机发生,你可以控制它的发生时间。

终于可以在合适的时候完全关闭 GC,防止 GC 产生的卡顿。

Unity - Scripting API: Scripting.GarbageCollector.GCMode

.NET 4.x Equivalent脚本运行时成为默认选项

.NET 4.x Equivalent脚本运行时现在成为了Unity新项目的默认选项。

旧版的脚本运行时(即.NET 3.5 Equivalent)已经被弃用,并且将在Unity 2019.x发布周期移除。.NET 4.x Equivalent和.NET 3.5 Equivalent脚本运行时都仍会在Unity 2018 LTS版得到支持。 如果你还没在自己的项目尝试全新的.NET 4.x Equivalent脚本运行时(在Unity 2018.2推出),它的新功能将是改变脚本运行时的最好原因,例如:在所有支持Mono和IL2CPP的Unity平台上,对所有.NET类库的API提供完整的TLS 1.2支持。

我们为减小项目大小进行了大量工作。例如在iOS系统上,使用新版脚本运行时的Unity 2018.3项目的整体构建大小和Unity 2018.2或更早版本(使用旧版脚本运行时)的项目大小差不多。 面向.NET 4.x脚本运行时的项目也支持使用开源的Roslyn编译器,能避免出现此前Mono C#编译器出现的Bug。

C# 7.3:Roslyn编译器

C# 7.3现在支持面向.NET 4.x脚本运行时的项目。这是因为我们改进了它与开源Roslyn C#编译器的兼容性,从而提供了最新C# 7.3的语言特性,并减少了编译时间。

简单说,.NET 4.x 将会使用微软开源的 Roslyn 编译器编译代码,完全支持新版本 C#。

用于重压缩下载资源包的运行时API

AssetBundle是包含平台特有资源(例如模型、纹理、预制件、音频剪辑以及甚至整个场景)的档案文件,这些资源都可以在运行时加载。AssetBundle可以减少可下载内容(DLC)的初始安装大小,确保资源针对最终用户的平台进行优化,并降低运行时内存压力。

Unity 2018.3提供了允许开发者创建和管理AssetBundle缓存系统的API。你可以向客户提供通过LZMA压缩的AssetBundle,然后客户将AssetBundle重新压缩为对运行时更友好的格式(即LZ4),就像使用我们的原生内置AssetBundle缓存系统一样。

正常需要引入一个 .NET 或 Native 压缩库来支持此功能,为了提高性能,通常会使用 Native 压缩库,但是要处理不同平台的编译问题。现在官方直接将内部的接口暴露出来,方便直接使用。

资源上传管线

Unity 2018.3之前,资源上传管线AUP仅处理纹理。从Unity 2018.3开始,AUP可以加载纹理和网格,但有部分例外情况:可读写纹理、可读写网格和压缩网格不能使用AUP。请注意:Unity 2018.2加入的纹理Mipmap流也使用AUP。

请在《优化加载性能:了解异步上传管线AUP》文章了解更多信息。

内存分析器

内存消耗量是关键的性能指标,对于低端移动设备等内存资源有限的平台来说尤为重要。

虽然Unity拥有优秀的性能工具,但仍在解决内存相关问题的方面存在不足。找到泄露内存和最大内存分配部分,或寻找问题原因都不是简单的任务。

因此,我们帮助开发者轻松地了解项目中内存发生的事件。通过使用全新内存分析器Memory Profiler,你将能够了解所有内存分配的详细信息。

你可以使用该工具来获取分析器截图,分析原生内存和托管内存的使用情况,从而在优化内存使用时做出更好的决定。它的功能也适用于调查C#和C++内存,了解不同分配之间的关系,了解Unity内部分配,以及处理内存较少的设备。

此功能可以方便地分析 Mono 内存的使用,以前并没有特别好的方法查找内存泄露。

注意:此功能目前是 Beta 状态,可能不稳定。

平台

移动平台的动态分辨率(适用于iOS和Android)

Unity 2018.3针对iOS/tvOS (Metal)和Android (Vulkan)加入了Dynamic Resolution动态分辨率功能,该功能可以动态缩放部分或全部渲染目标,以减少GPU上的工作负载。当性能数据提示游戏将因受GPU限制而降低帧率时,该功能会自动触发。在这种情况下,逐渐减小分辨率有助于保持稳定的帧率。当用户即将体验游戏的GPU密集型部分时,也可以手动触发该功能。在逐渐调整分辨率的过程中,动态分辨率的影响几乎无法注意到。

动态分辨率可以方便地提升游戏性能。

Unity - Manual: Dynamic resolution

TextMesh Pro

Unity 2018.3的TextMesh Pro是经过验证的资源包。它加入了高度优化的Font Generator字体生成器,可在运行时生成字形。你可以通过调用混合动态字体系统(Hybrid Dynamic Font System)来结合项目中的静态字体资源和动态字体资源。

TextMesh Pro 使用 Signed Distance Field 技术显示字体,可以任意调节字体的粗细,而不会影响显示。现在最新版本支持动态字体,也就是说中文终于可以非常方便地使用了,而不需要预先准备字体。

Signed Distance Field - 知乎

Project Tiny小游戏开发套件

Project Tiny是Unity的一个全新模块,提供了全新的运行时和编辑器模式,旨在构建可以即时加载而无需安装的游戏和体验。Project Tiny为开发者提供了快速创建高质量2D小游戏和可玩式广告所需的工具,创建出的游戏安装包非常之小,可以在各种移动设备上快速启动。

Project Tiny通过名为“Tiny Mode”的资源包提供。安装时,请打开Unity 2018.3的资源包管理器,选择Preview Packages,然后安装Tiny Mode。所有Unity的用户都可以使用该资源包,你可以在下载完成的预览资源包中找到Project Tiny用户手册,API文档和示例项目。更多信息及教程视频可以在Unity Solution页面《Unity 2018.3推出Project Tiny小游戏开发套件》了解。

终于有小游戏的支持了。

升级向导

Upgrading to Unity 2018.3

Support for logging unhandled exceptions in managed user threads

Before 2018.3, the Unity Editor did not log unhandled exceptions thrown in managed user threads. From 2018.3 onwards, unhandled exceptions thrown in managed user threads are logged on the Unity Editor console.

Because logging now includes all managed user threads, you may see exceptions that have always been thrown in your Projects, but were never emitted to the console until now.

简单说终于可以捕获并显示线程中的异常了,方便调试发现问题。

Upgraded PhysX from 3.3.1 to 3.4.2

Physics behaviour has changed and some Projects may behave differently with the new version. In particular:

The contact patches now contain up to 6 contacts in the Persistent Contact Manifold mode. This is an increase from 5 contacts per patch in previous versions. There is new code that merges patches in the manifold, and new code that selects contacts. Collisions appear to be a lot more accurate than before. You may need to work on Projects that rely on a particular arrangement of contacts to make them compatible with the new code. You are most likely to notice this when convex bodies collide with meshes and primitives.

A new algorithm is now used to compute contacts with terrains. It used to be special-cased, but now it’s the same mesh-primitive code that is used with MeshColliders. It’s robust, more accurate and performs well. However, it doesn’t support TerrainData.thickness, which means the tunneling effect with terrains is now possible. To avoid this, you need to enable continuous collision detection on the fast moving objects. Before that, if a body was discovered to be no deeper than TerrainData.thickness under the terrain, it was popped up automatically, but the normals were never correct. To get the old behaviour, uncheck the Enable Unified Heightmaps option in the Physics settings.

Negative mesh scaling no longer leads directly to mesh baking in all the cases. Concave meshes are not baked any more. However, Convex meshes still need to have scaling to be baked. With this change, negative scaling inverts the mesh normals when scale.x * scale.y * scale.z < 0. Additionally, non-trivial scaling like skew and shear still have to be baked, as before.

Convex mesh inflation is deprecated because it doesn’t seem to be needed with the new convex hull computation algorithm (Quickhull) that is more tolerant towards all sorts of imperfections in the input mesh.

这里详细介绍了物理引擎功能的变化。

C# compiler upgrade to Roslyn

Before 2018.3, the Unity Editor used the mono C# compiler (mcs) when compiling C# files in a project. From 2018.3 onwards, the Roslyn C# compiler (csc) is used for projects targeting the new scripting runtime (.NET 4.x Equivalent). Different behavior may be noticed from the switch to Roslyn:

C# 7.3 is the supported Additional warnings may be reported Response files for the Roslyn compiler should be named csc.rsp. See PlatformDependentCompilation.

Particle System bug fixes

Unity 2018.3 includes some particle bugs fixes and this can affect your projects that were created in a previous version.

When using non-uniform Transform scale on billboard particles, the Y and Z axes were inverted. This has now been fixed.

When using non-uniform Transform scale on mesh particles, rotation was applied after scaling. This was a regression in 2017.x. It behaved correctly in 5.6 and earlier, but was broken in the 2017 cycle. Fixing this bug corrects content created in 5.6 and earlier, but changes content created in 2017.x.

Spherical wind zones had the opposite effect on particles compared to trees. This has been corrected so the spherical wind zones now repel particles instead of attracting them. You can restore the previous behavior by negating the External Forces Multiplier, or the Wind Zone strength. Unity can’t change this automatically as Scenes with trees or directional wind zones could be incorrectly affected.

Upgrading to Unity 2018.2

Unity - Manual: Upgrading to Unity 2018.2

Photoshop Data file (PSD) import using transparency

When having actual transparency, Photoshop will tweak pixel colors to blend them with matte (background) color. The process of preparing alpha channels properly is described in our how to prepare alpha channels documentation.

You can ignore dilation in this document, the important part is the note that states that you want to have an “opaque” image with a separate alpha channel/mask (instead of having transparency). Unity tweaked colors to “remove” matte, but this has ceased as of 2018.2. If you had PSD with transparency you might start seeing white color on the edges. To fix this, consult the manual link above and make an actual alpha channel (instead of transparency).

Upgrading to Unity 2018.1

Unity - Manual: Upgrading to Unity 2018.1

BuildPipeline APIs

BuildPipeline APIs now return a BuildReport object instead of a string The BuildPipeline APIs, such as BuildPipeline.BuildPlayer, and BuildPipeline.BuildAssetBundles, previously returned a string. This was empty if the build succeeded and contained an error message if the build failed.

In 2018.1, this has been replaced with the new BuildReport object, which contains much richer information about the build process.

To check whether the build succeeded, retrieve the summary property of the report object, and check its result property - it will be BuildResult.Succeeded for a successful build. For example:

1
2
3
4
5
6
var report = BuildPipeline.BuildPlayer(...);

if (report.summary.result != BuildResult.Succeeded)
{
    throw new Exception("Build failed");
}

Plugins 目录中文件导入变化

Assets located in plugin folders will no longer be imported via specialized importers

Previously, assets located in plugin folders (for example, in directories with the extension .bundle, .plugin, or .folder) were imported using specialized importers. Textures were imported via texture importers, AudioClips via the audio importer, etc. Now all those assets will be imported using default importer, that means you won’t be able to reference those assets like you did before, because they no longer have a specialized type (Texture, AudioClip, etc). Plugin folders are contained packages, thus assets inside shouldn’t be accessible externally, except through plugin accessing techniques.

To continue using those assets, you’ll need to move them outside of your plugin folders.

粒子系统变化

Particle System Mesh particles applied the Pivot Offset value incorrectly The mathematical formula used for applying pivot offsets to Meshes was incorrect, and was inconsistent with how it worked for Billboard particles. To achieve the correct scale, the Pivot Offset should be multiplied by the size of the particle, so a Pivot Offset of 1 is equal to one full width of the particle.

For Meshes, the size was being multiplied twice, meaning the pivot amount was based on the squared particle size. This made it impossible to get consistent results in systems containing varying sized particles.

For systems using particles of equal size, the formula can be reverse-engineered to decide how much to adjust the pivot offset by, to compensate for this change in behavior:

Old formula: offset = size * size * pivot

New formula: offset = size * pivot

Therefore, if all particles are of equal size:

newOffset = pivot / size

In systems where the size varies between particles, a visual reassessment of the systems in question will be necessary.

未在文档中提到的

Unity 2018.1.0f2 开始,meta 文件中终于将这两个没用的字段删除了

1
2
timeCreated: 1508382703
licenseType: Free
  • timeCreated 字段会在每次资源发生变化时变化,非常不利于确定资源导入选项是否发生变化。
  • licenseType 完全是一个没有用的字段,根本不需要标记资源是在什么版本的 Unity 中导入的。