Version: 2021.3

MaterialPropertyBlock

class in UnityEngine

切换到手册

描述

要应用的材质值代码块。

MaterialPropertyBlock 由 Graphics.DrawMeshRenderer.SetPropertyBlock 使用。在 希望绘制具有相同材质,但属性 略有不同的多个对象时可使用它。例如,如果 要稍微更改绘制的每个网格的颜色。不支持更改渲染状态。

Unity 的地形引擎使用 MaterialPropertyBlock 绘制树;它们全都使用 相同材质,但是每棵树具有不同的颜色、缩放和风力系数。

传递给 Graphics.DrawMeshRenderer.SetPropertyBlock 的代码块将被复制,因此使用它的最高效方式是 创建一个代码块并将它重复用于所有 DrawMesh 调用。使用 SetFloatSetVectorSetColorSetMatrixSetTextureSetBuffer 可添加或替换值。

Note that this is not compatible with SRP Batcher. Using this in the Universal Render Pipeline (URP), High Definition Render Pipeline (HDRP) or a custom render pipeline based on the Scriptable Render Pipeline (SRP) will likely result in a drop in performance.

另请参阅:Graphics.DrawMeshMaterial

变量

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从属性代码块获取浮点数组。
GetIntThis method is deprecated. Use GetFloat or GetInteger instead.
GetIntegerGet an integer from the property block.
GetMatrix从属性代码块获取矩阵。
GetMatrixArray从属性代码块获取矩阵数组。
GetTexture从属性代码块获取纹理。
GetVector从属性代码块获取向量。
GetVectorArray从属性代码块获取向量数组。
HasBufferChecks if MaterialPropertyBlock has the ComputeBuffer property with the given name or name ID. To set the property, use SetBuffer.
HasColorChecks if MaterialPropertyBlock has the Color property with the given name or name ID. To set the property, use SetColor.
HasConstantBufferChecks if MaterialPropertyBlock has the ConstantBuffer property with the given name or name ID. To set the property, use SetConstantBuffer.
HasFloatChecks if MaterialPropertyBlock has the Float property with the given name or name ID. To set the property, use SetFloat.
HasIntThis method is deprecated. Use HasFloat or HasInteger instead.
HasIntegerChecks if MaterialPropertyBlock has the Integer property with the given name or name ID. To set the property, use SetInteger.
HasMatrixChecks if MaterialPropertyBlock has the Matrix property with the given name or name ID. This also works with the Matrix Array property. To set the property, use SetMatrix.
HasPropertyChecks if MaterialPropertyBlock has the property with the given name or name ID. To set the property, use one of the Set methods for MaterialPropertyBlock.
HasTextureChecks if MaterialPropertyBlock has the Texture property with the given name or name ID. To set the property, use SetTexture.
HasVectorChecks if MaterialPropertyBlock has the Vector property with the given name or name ID. This also works with the Vector Array property. To set the property, use SetVector.
SetBufferSet a buffer property.
SetColor设置颜色属性。
SetConstantBufferSets a ComputeBuffer or GraphicsBuffer as a named constant buffer for the MaterialPropertyBlock.
SetFloat设置浮点属性。
SetFloatArray设置浮点数组属性。
SetIntThis method is deprecated. Use SetFloat or SetInteger instead.
SetIntegerAdds a property to the block. If an integer property with the given name already exists, the old value is replaced.
SetMatrix设置矩阵属性。
SetMatrixArray设置矩阵数组属性。
SetTexture设置纹理属性。
SetVector设置向量属性。
SetVectorArray设置向量数组属性。