Custom ShaderGUI reference

Hi,
Looking for some reference for writing custom ShaderGUI’s for shaders made in shader graph like combining properties in dropdown menus etc. in inspector view
This:

isn`t very helpfull and im having issues to find working samples, nothing i’ve tried worked…

This is my latest attempt:

public class ShaderGUI_Skybox : ShaderGUI
{
    override public void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
    {

        bool showstuff = false;

        base.OnGUI(materialEditor, properties);
        EditorGUI.BeginChangeCheck();

        if (GUILayout.Button("Select GUI Color"))
        {
            showstuff = !showstuff;
            Debug.Log(showstuff);
        }


        if (EditorGUI.EndChangeCheck())
        {
            Debug.Log("End");
            if (showstuff)
            {
                // Sun
                EditorGUILayout.LabelField("Sun", EditorStyles.boldLabel);
                string[] SunReferences = { "_SunScale", "_SunConvergence", "_SunIntensity" };
                foreach (string Reference in SunReferences)
                {
                    MaterialProperty SunReference = ShaderGUI.FindProperty(Reference, properties);
                    materialEditor.ShaderProperty(SunReference, SunReference.displayName);
                }
            }
        }

Debug.Log works but the GUI in inspector does nuthing and im totally lost :)…

Got it,
EditorGUILayout.BeginFoldoutHeaderGroup(true, “Dropdown”);
and
EditorGUILayout.EndFoldoutHeaderGroup();
creates the dropdown menu i was looking for

public class ShaderGUI_Skybox : ShaderGUI
{
    bool showPosition = true;
    string status = "Settings";

    override public void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
    {
        showPosition = EditorGUILayout.BeginFoldoutHeaderGroup(showPosition, status);

        if (showPosition)
        { // Sun
            EditorGUILayout.LabelField("Sun", EditorStyles.boldLabel);
            string[] SunReferences = { "_SunScale", "_SunConvergence", "_SunIntensity" };
            foreach (string Reference in SunReferences)
            {
                MaterialProperty SunReference = ShaderGUI.FindProperty(Reference, properties);
                materialEditor.ShaderProperty(SunReference, SunReference.displayName);

                //EditorGUILayout.Separator();
            }

        }
        EditorGUILayout.EndFoldoutHeaderGroup();
    }
}
2 Likes