要应用的材质值代码块。
MaterialPropertyBlock 由 Graphics.DrawMesh 和 Renderer.SetPropertyBlock 使用。在
希望绘制具有相同材质,但属性
略有不同的多个对象时可使用它。例如,如果
要稍微更改绘制的每个网格的颜色。不支持更改渲染状态。
Unity 的地形引擎使用 MaterialPropertyBlock 绘制树;它们全都使用
相同材质,但是每棵树具有不同的颜色、缩放和风力系数。
传递给 Graphics.DrawMesh 或 Renderer.SetPropertyBlock 的代码块将被复制,因此使用它的最高效方式是
创建一个代码块并将它重复用于所有 DrawMesh 调用。使用 SetFloat、SetVector、SetColor、SetMatrix、SetTexture、SetBuffer 可添加或替换值。
另请参阅:Graphics.DrawMesh、Material。
isEmpty | 材质属性代码块是否为空?(只读) |
Clear | 清除材质属性值。 |
CopyProbeOcclusionArrayFrom | 此函数将整个源数组都复制到名为 unity_ProbesOcclusion 的 Vector4 属性数组中,用于实例化 Shadowmask 渲染。 |
CopySHCoefficientArraysFrom | 此函数将整个源数组都转换并复制到名为 unity_SHBb、unity_SHBb、unity_SHBb、unity_SHBb、unity_SHBb、unity_SHBb 和 unity_SHC 的 7 个 Vector4 属性数组中,用于实例化light probe渲染。 |
GetColor | 从属性代码块获取颜色。 |
GetFloat | 从属性代码块获取浮点数。 |
GetFloatArray | 从属性代码块获取浮点数组。 |
GetInt | 从属性代码块获取整数。 |
GetMatrix | 从属性代码块获取矩阵。 |
GetMatrixArray | 从属性代码块获取矩阵数组。 |
GetTexture | 从属性代码块获取纹理。 |
GetVector | 从属性代码块获取向量。 |
GetVectorArray | 从属性代码块获取向量数组。 |
SetBuffer | Set a buffer property. |
SetColor | 设置颜色属性。 |
SetConstantBuffer | Sets a ComputeBuffer or GraphicsBuffer as a named constant buffer for the MaterialPropertyBlock. |
SetFloat | 设置浮点属性。 |
SetFloatArray | 设置浮点数组属性。 |
SetInt | 向代码块添加属性。如果具有给定名称的整数属性已存在,则替换旧值。 |
SetMatrix | 设置矩阵属性。 |
SetMatrixArray | 设置矩阵数组属性。 |
SetTexture | 设置纹理属性。 |
SetVector | 设置向量属性。 |
SetVectorArray | 设置向量数组属性。 |
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.