ShaderVariantCollection 记录每个着色器中实际使用的着色器变体。
这用于着色器预加载(“warmup”),以便游戏能够确保在启动时(或在关卡加载时间)加载“实际需要”的
着色器变体,以避免稍后在游戏中出现着色器编译相关的暂时性中断。
In Unity, many shaders internally have multiple "variants", to account for different light modes, lightmaps, shadows and so on. These variants are identified by a shader pass type, and a set of shader keywords. See ShaderVariant.
ShaderVariantCollection 的典型用法是从编辑器(在 Graphics Settings 下)记录在播放会话期间使用的着色器变体,将它们另存为资源,然后将它们添加到预加载着色器列表(也在 Graphics Settings 中)。此外,您还可以对 ShaderVariantCollection 对象手动调用 WarmUp。
ShaderVariantCollection 一般替代旧 Shader.WarmupAllShaders 函数。
isWarmedUp | 此 ShaderVariantCollection 是否已预热?(只读) |
shaderCount | 此集合中的着色器数量(只读)。 |
variantCount | Number of total variants in this collection (Read Only). |
warmedUpVariantCount | Number of total variants in this collection that are already warmed up (Read Only). |
ShaderVariantCollection | 创建新的空着色器变体集合。 |
Add | 向集合中添加新的着色器变体。 |
Clear | 从集合中移除所有着色器变体。 |
Contains | 检测某个着色器变体是否在集合中。 |
Remove | Removes shader variant from the collection. |
WarmUp | Prewarms all shader variants in this shader variant collection. |
WarmUpProgressively | Prewarms the given number of shader variants in this shader variant collection. |
GetInstanceID | Gets the instance ID of the object. |
ToString | 返回对象的名称。 |
Destroy | 移除 GameObject、组件或资源。 |
DestroyImmediate | 立即销毁对象 /obj/。强烈建议您改用 Destroy。 |
DontDestroyOnLoad | 在加载新的 Scene 时,请勿销毁 Object。 |
FindAnyObjectByType | Retrieves any active loaded object of Type type. |
FindFirstObjectByType | Retrieves the first active loaded object of Type type. |
FindObjectOfType | 返回第一个类型为 type 的已加载的激活对象。 |
FindObjectsByType | Retrieves a list of all loaded objects of Type type. |
FindObjectsOfType | Gets a list of all loaded objects of Type type. |
Instantiate | 克隆 original 对象并返回克隆对象。 |
bool | 该对象是否存在? |
operator != | 比较两个对象是否引用不同的对象。 |
operator == | 比较两个对象引用,判断它们是否引用同一个对象。 |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.