FilterAttribute
Tell the shader system which shader keywords to include or remove from the build, based on the data field underneath.
読み終わるまでの所要時間 5 分最終更新 2ヶ月前
Definition
- Type: Class
- Namespace: UnityEditor.ShaderKeywordFilter
- Assembly: UnityEditor
- Inherits from: Attribute
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]public class FilterAttribute : Attribute
Remarks
This is the base filter attribute class. Use the derived attributes instead:
- SelectIfAttribute
- SelectIfNotAttribute
- RemoveIfAttribute
- RemoveIfNotAttribute
- SelectOrRemoveAttribute
- RemoveOrSelectAttribute
These filter attributes only apply to the build if they're attached to a serialized data field that's part of the type tree of a RenderPipelineAsset referenced by QualitySettings. The attributes give you control over which shader keywords Unity uses to build shader variants, based on render pipeline settings.
For example, by default the following shader code generates four different shader variants during the build:
#pragma multi_compile __ SHADOWS_LOW SHADOWS_MEDIUM SHADOWS_HIGH
If you use filter attributes, this can be adjusted to better suit the settings configuration of the project.
In the following example, when is , the filter attribute forces the keyword set to only contain the variant during the build.
forceLowShadowstrueSelectIfmulti_compileSHADOWS_LOWusing UnityEditor.ShaderKeywordFilter;[SelectIf(true, keywordNames: "SHADOWS_LOW")]bool forceLowShadows;
You can also exclude keywords from the build. In the following example, when is , the filter attribute removes .
enableHighShadowsfalseRemoveIfSHADOWS_HIGH[RemoveIf(false, keywordNames: "SHADOWS_HIGH")]bool enableHighShadows;
You can also select or remove more than one keyword at a time.
In the following example, when is , the filter attribute selects only the variant and a no shadows variant.
onlyHighOrNoShadowstrueSelectIfSHADOWS_HIGHThe empty string denotes the empty keyword. You can only select and remove the empty keyword together with another keyword, because on its own applies to all keyword sets with an empty keyword.
""""multi_compile[SelectIf(true, keywordNames: new string[] {"", "SHADOWS_HIGH"})]bool onlyHighOrNoShadows;
You can use with enum data. The following example removes the variant if is set to anything except .
RemoveIfNotSHADOWS_LOWshadowModeLowpublic enum ShadowMode{ Low, Med, High}[RemoveIfNot(ShadowMode.Low, keywordNames: "SHADOWS_LOW")]ShadowMode shadowMode;
You can use the argument to use filter attributes to override filtering you've previously set. Normally the first filter rule encountered in the type tree targeting a specific keyword takes effect, and Unity ignores any later attributes. If you use , attributes can force the later filter rule to be active instead.
overridePriorityoverridePriorityYou can add constraint attributes to filter attributes, to determine whether the filter rule is active in the current context. See GraphicsAPIConstraintAttribute and TagConstraintAttribute for more information.
Constructors
Constructor | Description |
|---|---|
| FilterAttribute(UnityEditor.ShaderKeywordFilter.FilterAction,UnityEditor.ShaderKeywordFilter.FilterAttribute.Precedence,UnityEditor.ShaderKeywordFilter.FilterAttribute.EvaluationMode,System.Object,System.String,System.Int32,System.String[]) | Tell the shader system which shader keywords to include in or exclude from the build, based on the data field underneath. |
Enums
Enum | Description |
|---|---|
| FilterAttribute.EvaluationMode | How Unity evaluates the shader keyword filter attribute state. |
| FilterAttribute.Precedence | The precedence rules of shader keyword filter attributes that are active on the same keywords. |