此材质的父级。
具有非空父级的材质称为材质变体。
材质变体将继承其父级的所有属性,并可以按属性基础覆盖它们。因此,更改材质属性的值将影响层次结构中下面的所有变体。
此属性仅在编辑器中可用,在构建的项目中,所有材质层次结构都将被扁平化。
其他资源:Material.IsChildOf,Material.IsPropertyOverriden,Material.IsPropertyLocked.
using UnityEngine; using UnityEditor;
public class Example : MonoBehaviour { #if UNITY_EDITOR [MenuItem("GameObject/Create Material Variant")] static void DuplicateMaterial() { Material selected = Selection.activeObject as Material; if (selected == null) return;
// Create a material variant from selected material // And override it's color to red Material material = new Material(selected); material.parent = selected; material.color = Color.red;
AssetDatabase.CreateAsset(material, "Assets/" + selected.name + " Variant.mat"); } #endif }