一次性加载所有的Shader.避免材质上的Shader丢失,5.X需要调用Shader.WarmupAllShaders

ShaderVariantCollection Document

Description

ShaderVariantCollection records which shader variants are actually used in each shader.

This is used for shader preloading (“warmup”), so that a game can make sure “actually required” shader variants are loaded at startup (or level load time), to avoid shader compilation related hiccups later on in the game.

In Unity, many shaders internally have multiple “variants”, to account for different light modes, lightmaps, shadows and so on. These variants are indentified by a shader pass type, and a set of shader keywords. See ShaderVariant.

Typical use of ShaderVariantCollection is to record the shader variants used during a play session from the editor (under Graphics Settings), save them out as an asset, and add to the list of preloaded shaders (again in Graphics Settings). Additionally, you could call WarmUp on a ShaderVariantCollection object manually.

ShaderVariantCollection generally replaces the old Shader.WarmupAllShaders function.

Note

对于Unity4.x版本,Shader的AssetBundle加载后只需LoadAll即可完成所有Shader的加载和解析,但对于Unity5.x版本,除执行LoadAllAssets操作外,还需要进行Shader.WarmupAllShaders操作,因为在Unity5.x版本中,Shader的解析和CreateGPUProgram操作是分离的。 – 摘录自UWA Unity加载模块深度解析(Shader篇)

参考文档

UNITY3D - 图形性能优化:优化着色器加载时间
Unity加载模块深度解析(Shader篇)