MaterialPropertyBlock 材质属性块

A block of material values to apply.


MaterialPropertyBlock is used by Graphics.DrawMesh. 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.


Unity's terrain engine uses MaterialPropertyBlock to draw trees; all of them use the same material, but each tree has different color, scale & wind factor.


For performance reasons, the property block can contain only a limited number of property values. Two 4x4 matrices, 7 vectors/colors or 14 floats can be stored in the block. Storage space for the values is shared, so storing one matrix leaves twice less space to store vectors and floats.


Graphics.DrawMesh copies the passed property block, so the most efficient way of using it is to create one block and reuse it for all DrawMesh calls. Use Clear to clear block's values, and AddFloat, AddVector, AddColor, AddMatrix to add values.

Graphics.DrawMesh 拷贝传递的属性块,因此最有效的方法是使用它来创建一个块并为所有DrawMesh调用再使用它。使用Clear来清除块的值,AddFloat,AddVector,AddColot,AddMatrix来添加值。

参见: Graphics.DrawMesh, Material.


Page last updated: 2011-3-1