实现在编辑器中,直接替换父节点下所有模型的材质球
public class CheckMaterials : MonoBehaviour
{
public Material mat;
[ContextMenu("Change")]
void Change()
{
GetChild(transform);
}
void GetChild(Transform t)
{
foreach (Transform item in t)
{
if (item.TryGetComponent(out MeshRenderer mr))
{
Material[] bufMat = new Material[mr.sharedMaterials.Length];
for (int i = 0; i < mr.sharedMaterials.Length; i++)
{
bufMat[i] = mat;
}
mr.sharedMaterials = bufMat;
}
GetChild(item);
}
}
}