您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

31 行
879 B

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum MaterialPropertyTarget
{
Renderer,
Material
}
[ExecuteInEditMode]
public class TestMpbPerMaterial : MonoBehaviour
{
public MaterialPropertyTarget materialPropertyTarget = MaterialPropertyTarget.Material;
public Color color;
// Update is called once per frame
void Start()
{
var meshRenderer = GetComponent<MeshRenderer>();
MaterialPropertyBlock mpb = new MaterialPropertyBlock();
mpb.SetColor("_BaseColor", color);
if (materialPropertyTarget == MaterialPropertyTarget.Renderer)
meshRenderer.SetPropertyBlock(mpb);
else
{
for (int i = 0; i < meshRenderer.sharedMaterials.Length; i++)
{
meshRenderer.SetPropertyBlock(mpb, i);
}
}
}
}