Version: 2023.1

MaterialPropertyBlock

class in UnityEngine

切换到手册

描述

要应用的材质值代码块。

MaterialPropertyBlock is used by Graphics.RenderMesh and Renderer.SetPropertyBlock. Use it in situations where you want to draw multiple objects with the same material, but slightly different properties. For example, if you want to slightly change the color of each mesh drawn. Changing the render state is not supported.

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

The block passed to Graphics.RenderMesh or Renderer.SetPropertyBlock is copied, so the most efficient way of using it is to create one block and reuse it for all DrawMesh calls. Use SetFloat, SetVector, SetColor, SetMatrix, SetTexture, SetBuffer to add or replace values.

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.

See Also: Graphics.RenderMesh, 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从属性代码块获取浮点数组。
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设置向量数组属性。
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961