Version: 2022.1

Material.SetOverrideTag

切换到手册
public void SetOverrideTag (string tag, string val);

参数

tag 要设置的标记的名称。
val 要设置的值的名称。用于清除重写标志的空字符串。

描述

对材质设置重写标记/值。

Will set a tag/value on the material that overrides the value of said tag from the shader. This can be used to make sure replacement shaders (such as rendering DepthNormals) work even if the original shader only supports a certain render type. For example if a shader only supports a specific render type but renders in many ways using keywords, SetOverrideTag can be used fom a custom material inspector to ensure that the material renders correctly even if the shader is replaced. Note that overriding the LightMode tag has no effect.

using UnityEngine;

public static class MaterialUtils { public enum BlendMode { Opaque, Cutout, Fade, Transparent }

public static void SetupBlendMode(Material material, BlendMode blendMode) { switch (blendMode) { case BlendMode.Opaque: material.SetOverrideTag("RenderType", ""); material.DisableKeyword("_ALPHATEST_ON"); material.renderQueue = -1; break; case BlendMode.Cutout: material.SetOverrideTag("RenderType", "TransparentCutout"); material.EnableKeyword("_ALPHATEST_ON"); material.renderQueue = 2450; break; } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961