Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Custom ShaderGUI reference

Discussion in 'Documentation' started by BayernMaik, Aug 10, 2020.

  1. BayernMaik

    BayernMaik

    Joined:
    Oct 15, 2019
    Posts:
    20
    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:
    https://docs.unity3d.com/Manual/SL-CustomShaderGUI.html
    isn`t very helpfull and im having issues to find working samples, nothing i've tried worked...


    This is my latest attempt:
    Code (CSharp):
    1. public class ShaderGUI_Skybox : ShaderGUI
    2. {
    3.     override public void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
    4.     {
    5.  
    6.         bool showstuff = false;
    7.  
    8.         base.OnGUI(materialEditor, properties);
    9.         EditorGUI.BeginChangeCheck();
    10.  
    11.         if (GUILayout.Button("Select GUI Color"))
    12.         {
    13.             showstuff = !showstuff;
    14.             Debug.Log(showstuff);
    15.         }
    16.  
    17.  
    18.         if (EditorGUI.EndChangeCheck())
    19.         {
    20.             Debug.Log("End");
    21.             if (showstuff)
    22.             {
    23.                 // Sun
    24.                 EditorGUILayout.LabelField("Sun", EditorStyles.boldLabel);
    25.                 string[] SunReferences = { "_SunScale", "_SunConvergence", "_SunIntensity" };
    26.                 foreach (string Reference in SunReferences)
    27.                 {
    28.                     MaterialProperty SunReference = ShaderGUI.FindProperty(Reference, properties);
    29.                     materialEditor.ShaderProperty(SunReference, SunReference.displayName);
    30.                 }
    31.             }
    32.         }
    Debug.Log works but the GUI in inspector does nuthing and im totally lost :)...
     
  2. BayernMaik

    BayernMaik

    Joined:
    Oct 15, 2019
    Posts:
    20
    Got it,
    EditorGUILayout.BeginFoldoutHeaderGroup(true, "Dropdown");
    and
    EditorGUILayout.EndFoldoutHeaderGroup();
    creates the dropdown menu i was looking for

    Code (CSharp):
    1.  
    2. public class ShaderGUI_Skybox : ShaderGUI
    3. {
    4.     bool showPosition = true;
    5.     string status = "Settings";
    6.  
    7.     override public void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
    8.     {
    9.         showPosition = EditorGUILayout.BeginFoldoutHeaderGroup(showPosition, status);
    10.  
    11.         if (showPosition)
    12.         { // Sun
    13.             EditorGUILayout.LabelField("Sun", EditorStyles.boldLabel);
    14.             string[] SunReferences = { "_SunScale", "_SunConvergence", "_SunIntensity" };
    15.             foreach (string Reference in SunReferences)
    16.             {
    17.                 MaterialProperty SunReference = ShaderGUI.FindProperty(Reference, properties);
    18.                 materialEditor.ShaderProperty(SunReference, SunReference.displayName);
    19.  
    20.                 //EditorGUILayout.Separator();
    21.             }
    22.  
    23.         }
    24.         EditorGUILayout.EndFoldoutHeaderGroup();
    25.     }
    26. }
    27.  
     
    toryjleo and Beauque like this.