public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)
        {
            Material material = materialEditor.target as Material;
            Shader   shader   = material.shader;

            isCutout        = material.GetInt("_BlendMode") == 1;
            isDithered      = material.GetInt("_BlendMode") == 2;
            isRefractive    = material.GetInt("_UseRefraction") == 1;
            isOutlined      = shader.name.Contains("Outline");
            isPatreonShader = shader.name.Contains("Patreon");
            isEyeTracking   = shader.name.Contains("EyeTracking");


            //Find all material properties listed in the script using reflection, and set them using a loop only if they're of type MaterialProperty.
            //This makes things a lot nicer to maintain and cleaner to look at.
            foreach (var property in GetType().GetFields(bindingFlags))
            {
                if (property.FieldType == typeof(MaterialProperty))
                {
                    try { property.SetValue(this, FindProperty(property.Name, props)); } catch { /*Is it really a problem if it doesn't exist?*/ }
                }
            }

            EditorGUI.BeginChangeCheck();
            {
                XSStyles.ShurikenHeaderCentered("XSToon v" + XSStyles.ver);
                material.SetShaderPassEnabled("Always", isRefractive);
                materialEditor.ShaderProperty(_AdvMode, new GUIContent("Shader Mode", "Setting this to 'Advanced' will give you access to things such as stenciling, and other expiremental/advanced features."));
                materialEditor.ShaderProperty(_Culling, new GUIContent("Culling Mode", "Changes the culling mode. 'Off' will result in a two sided material, while 'Front' and 'Back' will cull those sides respectively"));
                materialEditor.ShaderProperty(_TilingMode, new GUIContent("Tiling Mode", "Setting this to Merged will tile and offset all textures based on the Main texture's Tiling/Offset."));
                materialEditor.ShaderProperty(_BlendMode, new GUIContent("Blend Mode", "Blend mode of the material. (Opaque, transparent, cutout, etc.)"));
                materialEditor.ShaderProperty(_UseRefraction, new GUIContent("Refraction", "Should this material be refractive? (Warning, this can be expensive!)"));

                DoBlendModeSettings(material);
                DrawMainSettings(materialEditor);
                DrawDissolveSettings(materialEditor);
                DrawShadowSettings(materialEditor, material);
                DrawOutlineSettings(materialEditor);
                DrawNormalSettings(materialEditor);
                DrawSpecularSettings(materialEditor);
                DrawReflectionsSettings(materialEditor, material);
                DrawRefractionSettings(materialEditor);
                DrawEmissionSettings(materialEditor);
                DrawRimlightSettings(materialEditor);
                DrawHalfToneSettings(materialEditor);
                DrawTransmissionSettings(materialEditor);
                DrawAdvancedSettings(materialEditor);
                DrawPatreonSettings(materialEditor);
                XSStyles.DoFooter();
            }
        }
Exemplo n.º 2
0
        public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)
        {
            Material material = materialEditor.target as Material;
            Shader   shader   = material.shader;

            isDithered      = shader.name.Contains("Dithered");
            isCutout        = shader.name.Contains("Cutout") && !shader.name.Contains("A2C");
            isCutoutMasked  = shader.name.Contains("A2C") && shader.name.Contains("Masked");
            isOutlined      = shader.name.Contains("Outline");
            isPatreonShader = shader.name.Contains("Patreon");
            isEyeTracking   = shader.name.Contains("EyeTracking");

            //Find all material properties listed in the script using reflection, and set them using a loop only if they're of type MaterialProperty.
            //This makes things a lot nicer to maintain and cleaner to look at.
            foreach (var property in GetType().GetFields(bindingFlags))
            {
                if (property.FieldType == typeof(MaterialProperty))
                {
                    try{ property.SetValue(this, FindProperty(property.Name, props)); } catch { /*Is it really a problem if it doesn't exist?*/ }
                }
            }

            EditorGUI.BeginChangeCheck();
            {
                if (!isCutout && !isCutoutMasked)            // Do this to make sure that if you're using AlphaToCoverage that you fallback to cutout with 0.5 Cutoff if your shaders are blocked.
                {
                    material.SetFloat("_Cutoff", 0.5f);
                }

                XSStyles.ShurikenHeaderCentered("XSToon v" + XSStyles.ver);
                materialEditor.ShaderProperty(_AdvMode, new GUIContent("Shader Mode", "Setting this to 'Advanced' will give you access to things such as stenciling, and other expiremental/advanced features."));
                materialEditor.ShaderProperty(_Culling, new GUIContent("Culling Mode", "Changes the culling mode. 'Off' will result in a two sided material, while 'Front' and 'Back' will cull those sides respectively"));
                materialEditor.ShaderProperty(_TilingMode, new GUIContent("Tiling Mode", "Setting this to Merged will tile and offset all textures based on the Main texture's Tiling/Offset."));

                DrawMainSettings(materialEditor);
                DrawShadowSettings(materialEditor, material);
                DrawOutlineSettings(materialEditor);
                DrawNormalSettings(materialEditor);
                DrawSpecularSettings(materialEditor);
                DrawReflectionsSettings(materialEditor, material);
                DrawEmissionSettings(materialEditor);
                DrawRimlightSettings(materialEditor);
                DrawHalfToneSettings(materialEditor);
                DrawTransmissionSettings(materialEditor);
                DrawAdvancedSettings(materialEditor);
                DrawPatreonSettings(materialEditor);
                XSStyles.DoFooter();
            }
        }