Search Unity

[SOLVED] Custom Property Drawer without folding

Discussion in 'Immediate Mode GUI (IMGUI)' started by Netbandit, Aug 19, 2017.

  1. Netbandit

    Netbandit

    Joined:
    Feb 16, 2014
    Posts:
    18
    Hello,

    I have a custom property drawer to print an integer vector as read-only value.

    The code is like this:

    Code (CSharp):
    1.  
    2. [CustomPropertyDrawer(typeof(IntVector4))]
    3. public class IntVector4Drawer : PropertyDrawer
    4.   {
    5.     public override void OnGUI(Rect Position, SerializedProperty Property, GUIContent Label)
    6.     {
    7.       IntVector4 Vector = new IntVector4(
    8.         Property.FindPropertyRelative("mX").intValue,
    9.         Property.FindPropertyRelative("mY").intValue,
    10.         Property.FindPropertyRelative("mZ").intValue,
    11.         Property.FindPropertyRelative("mW").intValue
    12.         );
    13.      
    14.       EditorGUI.BeginProperty(Position, Label, Property);
    15.       Position = EditorGUI.PrefixLabel(Position, Label);
    16.       EditorGUI.PropertyField(Position, Property, new GUIContent(Vector.ToString()));
    17.       EditorGUI.EndProperty();
    18.    
    19.     }
    20.   }
    21.  
    Basically everything works: The values are visible in the inspector as read-only values. However the values have this little folding arrow at the side and I can fold and unfold them, even if there is no content to unfold. Is there any possibility to get rid of this folding symbol?

    This is an image:
    Folding.png
     
  2. LaireonGames

    LaireonGames

    Joined:
    Nov 16, 2013
    Posts:
    705
    If you want it read only then ditch all the property stuff and instead use:

    EditorGuiLayout.LabelField (or probably EditorGUI.LabelField in your case)
     
    Netbandit likes this.
  3. Netbandit

    Netbandit

    Joined:
    Feb 16, 2014
    Posts:
    18
    Thank you, it solves perfectly my issue here.

    The final code is:
    Code (CSharp):
    1.      
    2. public override void OnGUI(Rect Position, SerializedProperty Property, GUIContent Label)
    3. {
    4.   IntVector4 Vector = new IntVector4(
    5.     Property.FindPropertyRelative("mX").intValue,
    6.     Property.FindPropertyRelative("mY").intValue,
    7.     Property.FindPropertyRelative("mZ").intValue,
    8.     Property.FindPropertyRelative("mW").intValue
    9.     );
    10.  
    11.   Position = EditorGUI.PrefixLabel(Position, Label);
    12.   EditorGUI.LabelField(Position, Vector.ToString());    
    13. }
    14.  
    And this is how it looks now:
    hex.png
     
    LaireonGames likes this.
  4. LaireonGames

    LaireonGames

    Joined:
    Nov 16, 2013
    Posts:
    705
    No worries!