title: Unity PropertyDrawer for Serializable object
body: <p>I try to draw defualt inspector for serializable object <strong>manually</strong> , and <strong>Here is my code</strong>:</p>
  <pre><code>[System.Serializable]
  public class Item
  {
      public string Name;
      public int ID;
  }
  
  [System.Serializable]
  public class ItemGroup
  {
      public Item item;
      public int count;
  }
  
  public class Test : MonoBehaviour
  {
      public Item item;
      public ItemGroup itemGroup;
      public Item[] items;
      public ItemGroup[] itemGroups;
  }
  </code></pre>
  <p>The <strong>default inspector</strong> is look like this:</p>
  <p><a href="https://i.stack.imgur.com/tDqm1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tDqm1.png" alt="enter image description here" /></a></p>
  <p>Then I add the <code>PropertyDrawer</code> script for <code>Item</code> and <code>ItemGroup</code></p>
  <pre><code>[CustomPropertyDrawer(typeof(Item))]
  public class ItemDrawer : PropertyDrawer
  {
      public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
      {
          return EditorGUI.GetPropertyHeight(property, label);
      }
      public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
      {
          var style = new GUIStyle(EditorStyles.foldoutHeader);
          style.fontStyle = FontStyle.Normal;
          
          if (property.isExpanded = EditorGUI.BeginFoldoutHeaderGroup(position, property.isExpanded, label, style))
          {
              EditorGUI.indentLevel++;
              position.height = EditorGUIUtility.singleLineHeight;
              position.y += position.height;
              EditorGUI.PropertyField(position, property.FindPropertyRelative(&quot;Name&quot;));
              position.y += position.height;
              EditorGUI.PropertyField(position, property.FindPropertyRelative(&quot;ID&quot;));
              EditorGUI.indentLevel--;
          }
          EditorGUI.EndFoldoutHeaderGroup();
      }
  }
  
  [CustomPropertyDrawer(typeof(ItemGroup))]
  public class ItemGroupDrawer : PropertyDrawer
  {
      public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
      {
          return EditorGUI.GetPropertyHeight(property, label);
      }
  
      public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
      {
          var style = new GUIStyle(EditorStyles.foldoutHeader);
          style.fontStyle = FontStyle.Normal;
          var itemProperty = property.FindPropertyRelative(&quot;item&quot;);
          var countProperty = property.FindPropertyRelative(&quot;count&quot;);
  
          position.height = EditorGUIUtility.singleLineHeight;
          if (property.isExpanded = EditorGUI.BeginFoldoutHeaderGroup(position, property.isExpanded, label, style))
          {
              EditorGUI.indentLevel++;
              position.y += position.height;
              position.height = EditorGUI.GetPropertyHeight(itemProperty);
              EditorGUI.PropertyField(position, itemProperty, true);
              position.y += position.height;
              position.height = EditorGUIUtility.singleLineHeight;
              EditorGUI.PropertyField(position, countProperty);
              EditorGUI.indentLevel--;
          }
          EditorGUI.EndFoldoutHeaderGroup();
      }
  }
  </code></pre>
  <p><strong>Question 1:</strong> When <strong>Enable</strong> <code>ItemDrawer</code> and <strong>Disable</strong> <code>ItemGroupDrawer</code>, the indent of <code>Item</code> field is wrong, see below.How to make it correct both in <code>ItemGroup</code> class and Array?</p>
  <pre><code>[CustomPropertyDrawer(typeof(Item))] //Enable ItemDrawer
  //[CustomPropertyDrawer(typeof(ItemGroup))] //Disable ItemGroupDrawer
  </code></pre>
  <p><a href="https://i.stack.imgur.com/p22us.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/p22us.png" alt="enter image description here" /></a></p>
  <p><strong>Question 2</strong>: When enable both <code>ItemDrawer</code> and <code>ItemGroupDrawer</code>, there is a error:</p>
  <p>but the <strong>default inspector</strong> it did has foldout header</p>
  <p><strong>So how to use <code>PropertyDrawer</code> to draw <code>Item</code> and <code>ItemGroup</code>'s properties manually that make it look like default inspector?</strong></p>
  <p>I don't want to use <code>EditorGUI.PropertyField(position, property);</code></p>
  <p>I want to draw their properties one by one</p>
  <p><a href="https://i.stack.imgur.com/lHCkn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lHCkn.png" alt="enter image description here" /></a></p>