Custom inspector size problem


Today I was working on a custom editor script, but i’m having an issue. In fact when I add some EditorGUI foldouts, the inspector window size does not increase with the numbers of fouldouts. So here’s what I get:
Moreover, I can’t expand AK47’ foldouts.


Here’s my script:

using UnityEngine;
using UnityEditor;
using System.Collections;

class  CharacterEditor: Editor {

	public bool fold = false;

	private GUIContent
		deleteButtonContent = new GUIContent("-", "delete weapon"),
	    addButtonContent = new GUIContent("Create new weapon", "add a new weapon");

	bool[] weaponsFouldOut;
	private bool hasInspectorBeenInitialized = false;

	public override void OnInspectorGUI() {
		base.OnInspectorGUI ();
		Character character = (Character)target;

		if (!hasInspectorBeenInitialized) {
						weaponsFouldOut = new bool[character.GetWeapons ().Count];
			hasInspectorBeenInitialized = true;

		Rect space = EditorGUILayout.BeginHorizontal();
		//EditorGUILayout.TextArea(string.Empty, GUIStyle.none, GUILayout.Height(111));

		fold = EditorGUILayout.Foldout(fold, "Weapons");
		if(fold) {
			space.y += 16;
			space.x += 16;
			int i = 0;
		foreach (BaseWeapon weapon in character.GetWeapons()){
				weaponsFouldOut <em>= EditorGUI.Foldout(space, weaponsFouldOut*, weapon.m_WeaponName, true);*</em>

_ if (weaponsFouldOut == true)
* space.y += 16;
space.y += 16;

* }*
Thank you guys !

You should only use GUILayout and EditorGUILayout functions. If you still need to use normal GUI functions you should reserve a rect with GUILayoutUtility.GetRect