Search Unity

  1. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice
  2. We're running great holiday deals on subscriptions, swag and Asset Store packages! Take a peek at this blog for more information!
    Dismiss Notice
  3. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  4. Unity 2017.2 is now released.
    Dismiss Notice
  5. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  6. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  8. Unity 2017.3 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:
    755
    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:
    755
    bump.
     
  3. Peter77

    Peter77

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

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    755
    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:
    755
    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?
     
  6. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    755
    Coming back necro style. This works with GetPropertyHeight, but not with lists. Does anyone know about this?

    Example:

    Code (CSharp):
    1. //class one
    2. public class ReadOnlyAttribute : PropertyAttribute
    3. {
    4.  
    5. }
    6.  
    7. //class two
    8. [CustomPropertyDrawer(typeof(ReadOnlyAttribute))]
    9. public class ReadOnlyDrawer : PropertyDrawer
    10. {
    11.     public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
    12.     {
    13.         return EditorGUI.GetPropertyHeight(property, label, true);
    14.     }
    15.  
    16.     public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
    17.     {
    18.         using (new EditorGUI.DisabledScope(true))
    19.         {
    20.             EditorGUI.PropertyField(position, prop, true);
    21.         }
    22.     }
    23. }
    24.  
    25. //...another class...
    26.         [SerializeField, ReadOnly, Header(EditorConfig.RUNTIME_HEADER)]
    27.         private List<GameObject> m_Products = new List<GameObject>();
    28.      
    29.         [SerializeField, ReadOnly]
    30.         private ProductList list;
    31.  
    32.         [Serializable]
    33.         public class ProductList
    34.         {
    35.             [SerializeField]
    36.             public List<GameObject> m_Products = new List<GameObject>();
    37.         }
    38.  
    39.  
    ends up looking like this:

    [​IMG]

    Any ideas?

    Thanks!