Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more..
    Dismiss Notice
  3. Dismiss Notice

Question Invisible spacing with foldout layout

Discussion in 'Immediate Mode GUI (IMGUI)' started by fouratj, Jul 27, 2020.

  1. fouratj

    fouratj

    Joined:
    Sep 20, 2019
    Posts:
    9
    Hi there

    I'm trying to create a custom editor UI related to foldout style. Actually it work as expected beside the fact that i have an invisible spacing that is add to my editor window.such as

    upload_2020-7-27_6-34-37.png

    Not sure how to solve that spacing issue, i tried to substract from the position ligneValue, but it doesn't change anything

    Here's the code i wrote

    Code (CSharp):
    1. public class VariableReferenceEditor : PropertyDrawer
    2. {
    3.     SerializedProperty useConstant;
    4.     SerializedProperty constantValue;
    5.     SerializedProperty variable;
    6.  
    7.     public virtual UnityEngine.Object GetObjectField(SerializedProperty inProperty)
    8.     {
    9.         return null;
    10.     }
    11.  
    12.     public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    13.     {
    14.         Debug.Log(position.ToString());
    15.         EditorGUI.BeginProperty(position, label, property);
    16.         property.isExpanded = EditorGUILayout.Foldout(property.isExpanded, property.name);
    17.         if(!property.isExpanded)
    18.         {
    19.             return;
    20.         }
    21.  
    22.         EditorGUI.indentLevel++;
    23.  
    24.         useConstant = property.FindPropertyRelative("UseConstant");
    25.         constantValue = property.FindPropertyRelative("ConstantValue");
    26.         variable = property.FindPropertyRelative("Variable");
    27.  
    28.         useConstant.boolValue = EditorGUILayout.Toggle("Use constant", useConstant.boolValue);
    29.  
    30.         if (useConstant.boolValue)
    31.         {
    32.             EditorGUILayout.PropertyField(constantValue, new GUIContent("Constant Value"));
    33.         }
    34.         else
    35.         {
    36.             variable.objectReferenceValue = GetObjectField(variable);
    37.         }
    38.         EditorGUI.indentLevel--;
    39.         property.serializedObject.ApplyModifiedProperties();
    40.  
    41.         EditorGUI.EndProperty();
    42.  
    43.         EditorUtility.SetDirty(property.serializedObject.targetObject);
    44.     }
    45. }

    Any advice on that would be helpful

    Thanks
     
  2. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,203
  3. fouratj

    fouratj

    Joined:
    Sep 20, 2019
    Posts:
    9
    A small up for this thread if anyone know a way to solve this