The built-in MaterialPropertyDrawers are: ToggleDrawer, EnumDrawer, KeywordEnumDrawer, PowerSliderDrawer, IntRangeDrawer. In shader code, the "Drawer" suffix of the class name is not written; when Unity searches for the drawer class it adds "Drawer" automatically.

What is a parameter attribute

Parameter properties are written in the Properties statement block, written in a pair of square brackets, which allows the variables we declare to generate custom properties in the Unity Inspector window.

Flexible use can make our Inspector panel more concise and easy to understand. At the same time, the "shader_feature" we use is also implemented by the parameter attribute.

“[Header(Your Title Here)]” is a parameter property.

Properties
    {
				[Header(My Category)]
				...
				Your properties here
				...
		}

What are the parameter attributes and what are their uses

Toggle

Function: Used to implement shader_feature (a Shader file generates Shader variants during packaging). That is, the shader can have multiple manifestations. Much like precompilation in C.

v2-be5b8d7632b7a7656222d4e121f17bd8_720w.png

Shader "InspectorPath/shaderName"
{
		Properties
    {
        [Toggle] _Enable ("Enable ?", Float) = 0
    }
		SubShader
    {
        Pass
        {
            CGPROGRAM
            …
            #pragma shader_feature _ENABLE_ON
            …
						half4 frag (v2f i) : SV_Target
            {
                float4 col = white;

                #if _ENABLE_ON    
                    return col;
                #else  
										col  =  enableBehaviour;      
                    return col;
                #endif
            }
            ENDCG
        }
    }
}

Note: When using Toggle , if some variants (shader_feature) are not compiled during precompilation (that is, during the packaging process), we will switch to which uncompiled variant (shader_feature) during real-time operation Material will be lost. The reason is that Toggle will only generate the variants (shader_feature) that are being used during the packaging process, and the unused variants are discarded in order to save space.

If we want to generate all the variants during the pre-compilation process, and a character with multiple states needs to be switched in real time through code at runtime, then the following KeywordEnum fully meets our requirements .

KeywordEnum

Function: Use shader_feature and multi_compile at the same time. Direct multi-compilation generates all variants for subsequent real-time switching.

v2-264041a4b5894f7d25a54ad9f4819f96_720w.png

Shader "InspectorPath/shaderName"
{
    Properties
    {
				// Display a popup with Off, Red, Blue choices
        [KeywordEnum(Off, Red, Blue)]
        _Options ("Color Options", Float) = 0
    }
    SubShader
    {
        Pass
        {
            CGPROGRAM
             …
            
            #pragma multi_compile _OPTIONS_OFF _OPTIONS_RED _OPTIONS_BLUE
             …
            half4 frag (v2f i) : SV_Target
            {
                half4 col = tex2D(_MainTex, i.uv);
                
                #if _OPTIONS_OFF         
                    return col;
                #elif _OPTIONS_RED       
                    return col * float4(1, 0, 0, 1);
                #elif _OPTIONS_BLUE      
                    return col * float4(0, 0, 1, 1);
                #endif
            }
            ENDCG
        }
    }
}

Shader "InspectorPath/shaderName"
{
    Properties
    {
				// Display a popup with None,Add,Multiply choices,
        // and setup corresponding shader keywords.
        [KeywordEnum(None, Add, Multiply)] _Overlay("Overlay mode", Float) = 0
    }
    SubShader
    {
        Pass
        {
            CGPROGRAM
             …
            
            #pragma multi_compile _OPTIONS_OFF _OPTIONS_RED _OPTIONS_BLUE
             …
            
            ENDCG
        }
    }
}