Version: 2020.3
public void Clear ();

描述

清除材质属性值。

Graphics.DrawMesh 复制传递的属性代码块,因此使用它的最高效方式是 创建一个代码块并将它重复用于所有 DrawMesh 调用。使用 Clear 可清除代码块的值, 使用 SetFloatSetVectorSetColorSetMatrix 可添加值。

using UnityEngine;

public class Example : MonoBehaviour { Mesh aMesh; Material aMaterial = new Material(Shader.Find("VertexLit"));

void Update() { MaterialPropertyBlock materialProperty = new MaterialPropertyBlock();

// Clear any property and add a red color materialProperty.Clear(); materialProperty.SetColor("_Color", Color.red); Graphics.DrawMesh(aMesh, new Vector3(5, 0, 0), Quaternion.identity, aMaterial, 0, null, 0, materialProperty);

// Clear any property and add a green color materialProperty.Clear(); materialProperty.SetColor("_Color", Color.green); Graphics.DrawMesh(aMesh, new Vector3(-5, 0, 0), Quaternion.identity, aMaterial, 0, null, 0, materialProperty); } }