更新

环境

  • Unity 2017.4.2f2
  • Unity 2018.3.0b3
  • macOS 10.13.6

功能介绍

主要功能 Preview of 2018.3 features - Unity Forum

粒子系统升级 Particle System Improvements - Google 文档

升级文档

官方升级文档草案 DRAFT Upgrade Guide 2018.3 - Google 文档

文件

版本

版本文件 ProjectSettings/ProjectVersion.txt

Packages

1
2
3
4
5
The Unity Package Manager now uses the "Packages" sub-folder of the project to persist package configuration and future package management-related features.

The project manifest ("manifest.json") from the "UnityPackageManager" folder was moved to the "Packages" folder.

You can safely delete the "UnityPackageManager" folder if it is no longer needed, and update your source control configuration accordingly.

Packages 结构发生变化。

插件

删除过期失效且不更新的插件。

编译

导入过程中产生大量错误、警告与信息,按照错误、警告、信息依次处理。

编译错误

发现新版本存在 Bug:修改 Editor 目录下脚本并不会显示非 Editor 目录下脚本的编译错误,只有手动重新 Reimport 普通脚本触发编译错误才可以正确报错。


1
2
3
Cannot access protected member `UnityEngine.RuntimeAnimatorController.RuntimeAnimatorController()' via a qualifier of type `UnityEngine.RuntimeAnimatorController'. The qualifier must be of type `ChapterAnimItem' or derived from it

error CS1540

去除初始化 new RuntimeAnimatorController() 调用。


1
2
3
`TextureCompressionQuality' is an ambiguous reference between `UnityEngine.TextureCompressionQuality' and `UnityEditor.TextureCompressionQuality'

error CS0104

直接引用 UnityEditor 命名空间:using TextureCompressionQuality = UnityEditor.TextureCompressionQuality;


1
2
3
Component could not be loaded when loading game object. Cleaning up!

Object GameObject (named 'XXXXXX') has multiple entries of the same Object component. Removing it!

原有粒子特效 Prefab 中存在着废弃的粒子组件:

  • EllipsoidParticleEmitter (Deprecated)
  • ParticleAnimator(Deprecated)
  • ParticleRenderer(Deprecated)

以上粒子相关组件在 2018.1 标记为已废弃,在 2018.3 中被完全被移除。

编译警告

1
2
3
warning CS0618: `UnityEngine.Object.DestroyObject(UnityEngine.Object)' is obsolete: `use Object.Destroy instead.'
warning CS0618: `UnityEngine.TouchScreenKeyboard.done' is obsolete: `Property done is deprecated, use status instead'
warning CS0618: `UnityEngine.TouchScreenKeyboard.wasCanceled' is obsolete: `Property wasCanceled is deprecated, use status instead.'

修正过期 API

API 变化

Prefab 相关 API

由于 2018.3 支持嵌套 Prefab,因此 API 发生较大变化,需要额外处理

API 对应升级表格:

Unity 2017.4 Unity 2018.3
PrefabUtility.GetPrefabParent PrefabUtility.GetCorrespondingObjectFromSource
PrefabUtility.ReplacePrefab PrefabUtility.SavePrefabAsset
PrefabUtility.CreatePrefab PrefabUtility.SaveAsPrefabAsset
PrefabUtility.GetPrefabType PrefabUtility.GetPrefabAssetType PrefabUtility.GetPrefabInstanceStatus
PrefabUtility.FindPrefabRoot GetOutermostPrefabInstanceRoot if source is a Prefab instance or source.transform.root.gameObject if source is a Prefab Asset object.

BuildPipeline.BuildPlayer 返回值

1
2
3
Cannot implicitly convert type `UnityEditor.Build.Reporting.BuildReport' to `string'

error CS0029

BuildPipeline.BuildPlayer 的返回值由 string 改为 BuildReport,根据需要取其中的字段使用即可。

运行时

1
Particle System is trying to spawn on a mesh with zero surface area

Fading in an entire particle system - Unity Forum

It means your mesh has zero surface area and you are not using vertex placement mode. Does your mesh have any triangles? Surface area is the total surface area of all triangles on your mesh. Either switch to vertex mode or add some triangles.

实际原因是因为 ParticleSystem 中 ShapeModule 要求引用的 Mesh 必须开启 Read/Write 选项。

1
Mesh DLoadingPage_CameraFlashBase requires Read/Write Enabled to be set in the importer to work on the particle system shape module

Particle System 升级后需要启用 Mesh 的 Read/Write Enabled 开关,需要编写脚本处理这种情况。

注意:需要关闭 AssetPostprocessor 中的禁用 Read/Write 代码。

增加查找出问题特效脚本:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;

public static class MeshToolForParticle
{
    [MenuItem("Tools/ParticleSystem/FindScenes", false, 20)]
    public static void FindScenes()
    {
        var guids = AssetDatabase.FindAssets("t:Scene");

        foreach (var guid in guids)
        {
            string path = AssetDatabase.GUIDToAssetPath(guid);
            var scene = EditorSceneManager.OpenScene(path, OpenSceneMode.Single);
            var roots = scene.GetRootGameObjects();
            bool found = false;
            foreach (var go in roots)
            {
                found |= Find(go);
            }

            if (found)
            {
                Debug.Log(path);
            }
        }
    }

    [MenuItem("Tools/ParticleSystem/FindPrefabs", false, 20)]
    public static void FindPrefabs()
    {
        var guids = AssetDatabase.FindAssets("t:Prefab");

        foreach (var guid in guids)
        {
            string path = AssetDatabase.GUIDToAssetPath(guid);
            var prefab = AssetDatabase.LoadAssetAtPath<GameObject>(path);
            Find(prefab);
        }
    }

    private static bool Find(GameObject go)
    {
        bool found = false;
        var particles = go.GetComponentsInChildren<ParticleSystem>(true);
        foreach (var particle in particles)
        {
            if (particle.shape.enabled && particle.shape.shapeType == ParticleSystemShapeType.Mesh &&
                particle.shape.meshShapeType != ParticleSystemMeshShapeType.Vertex)
            {
                string prefabPath = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(particle);
                Debug.LogWarning(string.Format("Path: {0}\nPrefab: {1}", particle.gameObject.GetGameObjectPath(), prefabPath));
                found = true;
            }
        }

        return found;
    }
}

构建

Android

1
2
Failed getting available Android API levels. Make sure your android sdk tools version is 25 or higher and you have internet connection.
UnityEditor.Android.<StartGettingReleasedAPILevels>c__AnonStorey0:<>m__0() (at ?)

构建时报错,按照提示,直接点击 Update 按钮升级 Android SDK 即可。

iOS

iOS 构建完成后报告链接错误,仔细检查后发现链接库被 Git LFS 管理,在检出时并未被还原为二进制文件,而是保留文本指针内容。

执行 git lfs checkout 命令修正此问题。

新版本优化

经过测试,发现 Unity 2018.1 中终于把 meta 文件中无用的

1
2
timeCreated: 1523361353
licenseType: Pro

两个字段删除了,实际上 timeCreated 并不是指资源创建的时间,而是资源修改的时间。

TODO

1
2
3
NullReferenceException: Object reference not set to an instance of an object

SuperTextMesh.OnValidate () (at Assets/Plugins/Clavian/SuperTextMesh/Scripts/SuperTextMesh.cs:1012)

SuperTextMesh 需要升级


1
2
ExecuteAlways
ExecuteInEditMode

两个属性有变化,需要更新


1
2
3
HasCoreStatsInBuild is only valid when called while building the player!

UnityEditor.BuildPipeline:BuildAssetBundles(String, BuildAssetBundleOptions, BuildTarget) (at ?)

构建 AssetBundle 时有错误,不确定是由什么引起的


1
2
3
4
5
Your multi-scene setup may be improved by tending to the following issues:
Multiple scenes baked with Auto enabled can appear differently in Play mode when reloading them. Consider disabling Auto and rebaking.

Your current multi-scene setup has inconsistent Lighting settings which may lead to different lighting when loading scenes individually or in a different order! Consider homogenizing the following:
1/2 scenes have Auto baking enabled.

统一所有场景的光照设置


1
`UnityEditor.AndroidBuildSystem.Internal' is obsolete: `Internal build system is deprecated. Please use Gradle instead'

需要转换项目到 Gradle


1
warning CS0618: `UnityEngine.WWW' is obsolete: `Use UnityWebRequest, a fully featured replacement which is more efficient and has additional features'

暂时禁用 WWW 过期警告,需要升级到新版本 API。