Search Unity

Question In editor script when using GUI.backgroundColor the EditorGUILayout.Foldout have no affect how to ?

Discussion in 'Immediate Mode GUI (IMGUI)' started by Chocolade, Jan 25, 2023.

  1. Chocolade

    Chocolade

    Joined:
    Jun 19, 2013
    Posts:
    933
    Code (csharp):
    1.  
    2. bool showPosition = false;
    3.         public override void OnInspectorGUI()
    4.         {
    5.             BezierUtils.DrawSplineInspectorGUI(allSplines);
    6.  
    7.             showPosition = EditorGUILayout.Foldout(showPosition, "Randomize");
    8.             if (showPosition)
    9.                 GUI.backgroundColor = Color.red;
    10.             if (GUILayout.Button("Generate Random Spline Path"))
    11.             {
    12.  
    13.             }
    14.         }
    15.  
    before adding the line:

    Code (csharp):
    1.  
    2. GUI.backgroundColor = Color.red;
    3.  
    i could press the Foldout arrow and collapse or expand the showPosition but after adding the backgroundColor line it's not collapsing/expanding anymore it's all the time collapsed and just changing the button color.

    i mean that i see the button all the time and the foldout is like a toggle switch that change the button color.

    instead, i want the button to be colored in red all the time and using the foldout to show/not show the button.
     
  2. oscarAbraham

    oscarAbraham

    Joined:
    Jan 7, 2013
    Posts:
    431
    You missed some brackets in your condition:
    Code (CSharp):
    1. bool showPosition = false;
    2.         public override void OnInspectorGUI()
    3.         {
    4.             BezierUtils.DrawSplineInspectorGUI(allSplines);
    5.             showPosition = EditorGUILayout.Foldout(showPosition, "Randomize");
    6.             if (showPosition)
    7.             {
    8.                 GUI.backgroundColor = Color.red;
    9.                 if (GUILayout.Button("Generate Random Spline Path"))
    10.                 {
    11.                 }
    12.             }
    13.         }