Search Unity

  1. Engage, network and learn at Unite Austin 2017, Oct 3 - 5. Get your ticket today!
    Dismiss Notice
  2. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  3. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  4. Unity 2017.1 is now released.
    Dismiss Notice
  5. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  6. Unity 2017.2 beta is now available for download.
    Dismiss Notice

EditorGUI.DisabledScope PropertyField Not Expanding On Disable

Discussion in 'Scripting' started by Nigey, Sep 8, 2017.

  1. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    749
    Hi Guys,

    I've said the whole thing in the title. When I use any of the following:

    Code (CSharp):
    1. [CustomPropertyDrawer(typeof(ReadOnlyAttribute))]
    2. public class ReadOnlyDrawer : PropertyDrawer
    3. {
    4.     public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
    5.     {
    6.         using (new EditorGUI.DisabledScope(true))
    7.         {
    8.             EditorGUI.PropertyField(position, prop, true);
    9.         }
    10.     }
    11. }
    Code (CSharp):
    1. [CustomPropertyDrawer(typeof(ReadOnlyAttribute))]
    2. public class ReadOnlyDrawer : PropertyDrawer
    3. {
    4.     public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
    5.     {
    6.         GUI.enabled = false;
    7.         EditorGUI.PropertyField(position, prop, true);
    8.         GUI.enabled = true;
    9.     }
    10. }
    Code (CSharp):
    1. [CustomPropertyDrawer(typeof(ReadOnlyAttribute))]
    2. public class ReadOnlyDrawer : PropertyDrawer
    3. {
    4.     public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
    5.     {
    6.         EditorGUI.BeginDisabledGroup(true);
    7.         EditorGUI.PropertyField(position, prop, true);
    8.     }
    9. }
    I get this result:

    [​IMG]

    It works perfectly with fields that cover one single 'line', but with classes that can be expanded it causes that result.

    Any ideas?
     
  2. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    749
    bump.
     
  3. Peter77

    Peter77

    Joined:
    Jun 12, 2013
    Posts:
    919
    Did you override GetPropertyHeight to return the actual height of the expanded GUI?
     
  4. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    749
    I haven't yet. So I need to find that. That's great, thanks. I'll try it out and put either an answer, or more questions here.
     
  5. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    749
    Okay, well that theory works, in theory. There doesn't seem to be many instances of people complaining about the same thing when it comes to creating PropertyDrawers of class variables that contain lists/other class vars ect. People tend to be just increasing the height by a flat number. Is there a way to find out the actual height of the property? As mine contains a class which contains several lists and another class, and I want this dynamic. Is there a clean way?