66
77public class FlatLitToonLiteInspector : ShaderGUI
88{
9-
10- public enum OutlineMode
11- {
12- None ,
13- Tinted ,
14- Colored
15- }
16-
17- public enum BlendMode
9+ public enum CullingMode
1810 {
19- Opaque ,
20- Cutout ,
21- Fade , // Old school alpha-blending mode, fresnel does not affect amount of transparency
22- Transparent // Physically plausible transparency mode, implemented as alpha pre-multiply
11+ Off ,
12+ Front ,
13+ Back
2314 }
2415
25- MaterialProperty blendMode ;
2616 MaterialProperty mainTexture ;
2717 MaterialProperty color ;
2818 MaterialProperty colorMask ;
2919 MaterialProperty shadow ;
3020 MaterialProperty emissionMap ;
3121 MaterialProperty emissionColor ;
3222 MaterialProperty normalMap ;
23+ MaterialProperty alphaCutout ;
3324 MaterialProperty alphaCutoff ;
25+ MaterialProperty cullingMode ;
3426
35- public override void OnGUI ( MaterialEditor materialEditor , MaterialProperty [ ] props )
27+ public override void OnGUI ( MaterialEditor materialEditor , MaterialProperty [ ] properties )
3628 {
3729 { //Find Properties
38- blendMode = FindProperty ( "_Mode" , props ) ;
39- mainTexture = FindProperty ( "_MainTex" , props ) ;
40- color = FindProperty ( "_Color" , props ) ;
41- colorMask = FindProperty ( "_ColorMask" , props ) ;
42- shadow = FindProperty ( "_Shadow" , props ) ;
43- emissionMap = FindProperty ( "_EmissionMap" , props ) ;
44- emissionColor = FindProperty ( "_EmissionColor" , props ) ;
45- normalMap = FindProperty ( "_BumpMap" , props ) ;
46- alphaCutoff = FindProperty ( "_Cutoff" , props ) ;
30+ mainTexture = FindProperty ( "_MainTex" , properties ) ;
31+ color = FindProperty ( "_Color" , properties ) ;
32+ colorMask = FindProperty ( "_ColorMask" , properties ) ;
33+ shadow = FindProperty ( "_Shadow" , properties ) ;
34+ emissionMap = FindProperty ( "_EmissionMap" , properties ) ;
35+ emissionColor = FindProperty ( "_EmissionColor" , properties ) ;
36+ normalMap = FindProperty ( "_BumpMap" , properties ) ;
37+ alphaCutout = FindProperty ( "_AlphaTest" , properties ) ;
38+ alphaCutoff = FindProperty ( "_Cutoff" , properties ) ;
39+ cullingMode = FindProperty ( "_Cull" , properties ) ;
4740 }
48-
41+
4942 Material material = materialEditor . target as Material ;
5043
51- { //Shader Properties GUI
52- EditorGUIUtility . labelWidth = 0f ;
53-
54- EditorGUI . BeginChangeCheck ( ) ;
55- {
56- EditorGUI . showMixedValue = blendMode . hasMixedValue ;
57- var bMode = ( BlendMode ) blendMode . floatValue ;
5844
59- EditorGUI . BeginChangeCheck ( ) ;
60- bMode = ( BlendMode ) EditorGUILayout . Popup ( "Rendering Mode" , ( int ) bMode , Enum . GetNames ( typeof ( BlendMode ) ) ) ;
61- if ( EditorGUI . EndChangeCheck ( ) )
62- {
63- materialEditor . RegisterPropertyChangeUndo ( "Rendering Mode" ) ;
64- blendMode . floatValue = ( float ) bMode ;
45+ //Shader Properties GUI
46+ EditorGUIUtility . labelWidth = 0f ;
6547
66- foreach ( var obj in blendMode . targets )
67- {
68- SetupMaterialWithBlendMode ( ( Material ) obj , ( BlendMode ) material . GetFloat ( "_Mode" ) ) ;
69- }
70- }
48+ EditorGUI . BeginChangeCheck ( ) ;
49+ {
50+ EditorGUI . showMixedValue = cullingMode . hasMixedValue ;
51+ var cMode = ( CullingMode ) cullingMode . floatValue ;
7152
72- EditorGUI . showMixedValue = false ;
53+ EditorGUI . BeginChangeCheck ( ) ;
54+ cMode = ( CullingMode ) EditorGUILayout . Popup ( "Culling Mode" , ( int ) cMode , Enum . GetNames ( typeof ( CullingMode ) ) ) ;
55+ if ( EditorGUI . EndChangeCheck ( ) )
56+ {
57+ materialEditor . RegisterPropertyChangeUndo ( "Rendering Mode" ) ;
58+ cullingMode . floatValue = ( float ) cMode ;
59+ }
60+ EditorGUI . showMixedValue = false ;
61+ EditorGUILayout . Space ( ) ;
7362
63+ materialEditor . TexturePropertySingleLine ( new GUIContent ( "Main Texture" , "Main Color Texture (RGB)" ) , mainTexture , color ) ;
64+ EditorGUI . indentLevel += 1 ;
65+ materialEditor . TexturePropertySingleLine ( new GUIContent ( "Color Mask" , "Masks Color Tinting (G)" ) , colorMask ) ;
66+ EditorGUI . indentLevel -= 1 ;
7467
75- materialEditor . TexturePropertySingleLine ( new GUIContent ( "Main Texture" , "Main Color Texture (RGB)" ) , mainTexture , color ) ;
76- EditorGUI . indentLevel += 2 ;
77- if ( ( BlendMode ) material . GetFloat ( "_Mode" ) == BlendMode . Cutout )
78- materialEditor . ShaderProperty ( alphaCutoff , "Alpha Cutoff" , 2 ) ;
79- materialEditor . TexturePropertySingleLine ( new GUIContent ( "Color Mask" , "Masks Color Tinting (G)" ) , colorMask ) ;
80- EditorGUI . indentLevel -= 2 ;
81- materialEditor . TexturePropertySingleLine ( new GUIContent ( "Normal Map" , "Normal Map (RGB)" ) , normalMap ) ;
82- materialEditor . TexturePropertySingleLine ( new GUIContent ( "Emission" , "Emission (RGB)" ) , emissionMap , emissionColor ) ;
83- EditorGUI . BeginChangeCheck ( ) ;
84- materialEditor . TextureScaleOffsetProperty ( mainTexture ) ;
85- if ( EditorGUI . EndChangeCheck ( ) )
86- emissionMap . textureScaleAndOffset = mainTexture . textureScaleAndOffset ;
87-
88- EditorGUILayout . Space ( ) ;
89- materialEditor . ShaderProperty ( shadow , "Shadow" ) ;
68+ materialEditor . TexturePropertySingleLine ( new GUIContent ( "Normal Map" , "Normal Map (RGB)" ) , normalMap ) ;
69+ materialEditor . TexturePropertySingleLine ( new GUIContent ( "Emission" , "Emission (RGB)" ) , emissionMap , emissionColor ) ;
70+ EditorGUI . BeginChangeCheck ( ) ;
71+ materialEditor . TextureScaleOffsetProperty ( mainTexture ) ;
72+ if ( EditorGUI . EndChangeCheck ( ) )
73+ {
74+ emissionMap . textureScaleAndOffset = mainTexture . textureScaleAndOffset ;
9075 }
91- EditorGUI . EndChangeCheck ( ) ;
92- }
9376
94- }
77+ EditorGUILayout . Space ( ) ;
78+ EditorGUILayout . Space ( ) ;
79+ materialEditor . ShaderProperty ( alphaCutout , "Alpha Cutout" , 0 ) ;
80+ if ( material . GetFloat ( "_AlphaTest" ) != 0 )
81+ {
82+ materialEditor . ShaderProperty ( alphaCutoff , "Alpha Cutoff" , 2 ) ;
83+ }
9584
96- public static void SetupMaterialWithBlendMode ( Material material , BlendMode blendMode )
97- {
98- switch ( ( BlendMode ) material . GetFloat ( "_Mode" ) )
99- {
100- case BlendMode . Opaque :
101- material . SetOverrideTag ( "RenderType" , "" ) ;
102- material . SetInt ( "_SrcBlend" , ( int ) UnityEngine . Rendering . BlendMode . One ) ;
103- material . SetInt ( "_DstBlend" , ( int ) UnityEngine . Rendering . BlendMode . Zero ) ;
104- material . SetInt ( "_ZWrite" , 1 ) ;
105- material . DisableKeyword ( "_ALPHATEST_ON" ) ;
106- material . DisableKeyword ( "_ALPHABLEND_ON" ) ;
107- material . DisableKeyword ( "_ALPHAPREMULTIPLY_ON" ) ;
108- material . renderQueue = - 1 ;
109- break ;
110- case BlendMode . Cutout :
111- material . SetOverrideTag ( "RenderType" , "TransparentCutout" ) ;
112- material . SetInt ( "_SrcBlend" , ( int ) UnityEngine . Rendering . BlendMode . One ) ;
113- material . SetInt ( "_DstBlend" , ( int ) UnityEngine . Rendering . BlendMode . Zero ) ;
114- material . SetInt ( "_ZWrite" , 1 ) ;
115- material . EnableKeyword ( "_ALPHATEST_ON" ) ;
116- material . DisableKeyword ( "_ALPHABLEND_ON" ) ;
117- material . DisableKeyword ( "_ALPHAPREMULTIPLY_ON" ) ;
118- material . renderQueue = ( int ) UnityEngine . Rendering . RenderQueue . AlphaTest ;
119- break ;
120- case BlendMode . Fade :
121- material . SetOverrideTag ( "RenderType" , "Transparent" ) ;
122- material . SetInt ( "_SrcBlend" , ( int ) UnityEngine . Rendering . BlendMode . SrcAlpha ) ;
123- material . SetInt ( "_DstBlend" , ( int ) UnityEngine . Rendering . BlendMode . OneMinusSrcAlpha ) ;
124- material . SetInt ( "_ZWrite" , 0 ) ;
125- material . DisableKeyword ( "_ALPHATEST_ON" ) ;
126- material . EnableKeyword ( "_ALPHABLEND_ON" ) ;
127- material . DisableKeyword ( "_ALPHAPREMULTIPLY_ON" ) ;
128- material . renderQueue = ( int ) UnityEngine . Rendering . RenderQueue . Transparent ;
129- break ;
130- case BlendMode . Transparent :
131- material . SetOverrideTag ( "RenderType" , "Transparent" ) ;
132- material . SetInt ( "_SrcBlend" , ( int ) UnityEngine . Rendering . BlendMode . One ) ;
133- material . SetInt ( "_DstBlend" , ( int ) UnityEngine . Rendering . BlendMode . OneMinusSrcAlpha ) ;
134- material . SetInt ( "_ZWrite" , 0 ) ;
135- material . DisableKeyword ( "_ALPHATEST_ON" ) ;
136- material . DisableKeyword ( "_ALPHABLEND_ON" ) ;
137- material . EnableKeyword ( "_ALPHAPREMULTIPLY_ON" ) ;
138- material . renderQueue = ( int ) UnityEngine . Rendering . RenderQueue . Transparent ;
139- break ;
85+ EditorGUILayout . Space ( ) ;
86+ materialEditor . ShaderProperty ( shadow , "Shadow" ) ;
14087 }
141- }
88+ EditorGUI . EndChangeCheck ( ) ;
14289
143- public static void SetupMaterialWithOutlineMode ( Material material , OutlineMode outlineMode )
144- {
145- switch ( ( OutlineMode ) material . GetFloat ( "_OutlineMode" ) )
146- {
147- case OutlineMode . None :
148- material . EnableKeyword ( "NO_OUTLINE" ) ;
149- material . DisableKeyword ( "TINTED_OUTLINE" ) ;
150- material . DisableKeyword ( "COLORED_OUTLINE" ) ;
151- break ;
152- case OutlineMode . Tinted :
153- material . DisableKeyword ( "NO_OUTLINE" ) ;
154- material . EnableKeyword ( "TINTED_OUTLINE" ) ;
155- material . DisableKeyword ( "COLORED_OUTLINE" ) ;
156- break ;
157- case OutlineMode . Colored :
158- material . DisableKeyword ( "NO_OUTLINE" ) ;
159- material . DisableKeyword ( "TINTED_OUTLINE" ) ;
160- material . EnableKeyword ( "COLORED_OUTLINE" ) ;
161- break ;
162- default :
163- break ;
164- }
16590 }
16691}
0 commit comments