public void drawGUI()
    {
        if (Event.current.commandName == "ObjectSelectorClosed" && EditorGUIUtility.GetObjectPickerControlID() == instanceID)
        {
            Object selection = EditorGUIUtility.GetObjectPickerObject();
            if (selection as GameObject != null)
            {
                AssetPreview.SetPreviewTextureCacheSize(1000);
                libraryItemList.Add(new LibraryItem(selection as GameObject, this));
                instanceID = -1;
            }
        }

        GUILayout.Label("Library", EditorStyles.boldLabel);
        EditorGUILayout.BeginHorizontal();

        if (GUILayout.Button("Add prefab to library"))
        {
            instanceID = window.GetInstanceID();
            EditorGUIUtility.ShowObjectPicker <GameObject>(null, false, "", instanceID);
        }
        EditorGUILayout.EndHorizontal();
        GUILayout.Label("Scale: ");
        iconSize = EditorGUILayout.Slider(iconSize, 48, 128);

        float windowWidth = EditorGUIUtility.currentViewWidth;
        int   maxInWidth  = (int)Mathf.Floor(windowWidth / iconSize);
        int   maxInHeight = (int)Mathf.Ceil(((float)libraryItemList.Count) / maxInWidth);

        libraryScrollPos = EditorGUILayout.BeginScrollView(libraryScrollPos, false, false, GUILayout.Width(windowWidth), GUILayout.Height(iconSize * maxInHeight), GUILayout.MaxHeight(400));

        EditorGUILayout.BeginVertical();
        for (int i = 0; i < maxInHeight; i++)
        {
            EditorGUILayout.BeginHorizontal();
            for (int j = i * maxInWidth; j < i * maxInWidth + maxInWidth; j++)
            {
                if (j < libraryItemList.Count)
                {
                    libraryItemList[j].Draw(new Vector2(iconSize, iconSize));
                }
                else
                {
                    GUILayout.Button("", GUIStyle.none, GUILayout.Width(iconSize), GUILayout.Height(iconSize));
                }
            }
            EditorGUILayout.EndHorizontal();
        }
        EditorGUILayout.EndVertical();

        EditorGUILayout.EndScrollView();
    }
 public PrefabPainterLibrary(PrefabPainter window)
 {
     instanceID  = window.GetInstanceID();
     this.window = window;
 }