Search Unity

(Case 1332297) The default ReorderableList is not correct in PropertyDrawer

Discussion in 'Editor & General Support' started by watsonsong, Apr 28, 2021.

  1. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    It seems the custom PropertyDrawer is not working correct with the default ReorderableList.
    I write a custom PropertyDrawer like this:
    Code (CSharp):
    1.  
    2. [CustomPropertyDrawer(typeof(TestData))]
    3. public class TestDataDrawer : PropertyDrawer
    4. {
    5.     /// <inheritdoc/>
    6.     public override void OnGUI(
    7.         Rect position, SerializedProperty property, GUIContent label)
    8.     {
    9.         using var p = new EditorGUI.PropertyScope(
    10.             position, label, property);
    11.         label = p.content;
    12.  
    13.         EditorGUI.PropertyField(position, property, label, true);
    14.     }
    15.  
    16.     /// <inheritdoc/>
    17.     public override float GetPropertyHeight(
    18.         SerializedProperty property, GUIContent label)
    19.     {
    20.         return EditorGUI.GetPropertyHeight(property, label, true);
    21.     }
    22. }
    The 'TestData' include an array, which default edtior is a reorderable list in unity 2020.
    Code (CSharp):
    1. [Serializable]
    2. public class TestData
    3. {
    4.     [SerializeField]
    5.     private int test;
    6.  
    7.     [SerializeField]
    8.     private Vector2[] vectors;
    9.  
    10.     [SerializeField]
    11.     private float number;
    12. }
    13.  
    But the inspector show incorrect with the vector array.
     

    Attached Files: