Search Unity

Editor GUILayout gets f*cked when you DrawPreviewTexture()

Discussion in 'Editor & General Support' started by unity_P-dQObz0sCT9rQ, Dec 14, 2019.

  1. unity_P-dQObz0sCT9rQ

    unity_P-dQObz0sCT9rQ

    Joined:
    Aug 28, 2019
    Posts:
    6
    Hello,

    I'm making a skin management tool and in the custom editor, when i add texture previews, the layout stretches outside the screen!

    I've tried setting the width of both the horizontal and vertical layout, and toggling expand, and using GUILayout.box, burt the problem persists.

    Hers is the editor without the previews:


    Here is after the previews display:


    I have to stretch is very far before the horizontal scrollbar disappears:



    The textures are like this:
    HoerizontalLayout
    -VerticalLayout

    --Prefix
    --ObjectField
    --DrawPreviewTexture

    -EndVerticalLayout
    EndHorizontalLayout

    here is the problem code:

    Code (CSharp):
    1.  
    2. GUILayout.BeginHorizontal();
    3. EditorGUILayout.PrefixLabel("Skin Name: ");
    4. edit.skinName = EditorGUILayout.TextField(edit.skinName);
    5. GUILayout.EndHorizontal();
    6.  
    7. GUILayout.BeginHorizontal();
    8.  
    9. GUILayout.BeginVertical("Box");
    10. EditorGUILayout.PrefixLabel("Panel Sprite");
    11. skinManager.panelSprite = (Sprite)EditorGUILayout.ObjectField(skinManager.panelSprite,                                                                                                                                           typeof(Sprite), false);
    12. if(skinManager.panelSprite != null)
    13. {
    14.            rect = EditorGUILayout.GetControlRect();
    15.            rect = new Rect(rect.x, rect.y - 1, 100, 100);
    16.            EditorGUI.DrawPreviewTexture(rect, skinManager.panelSprite.texture,null , ScaleMode.ScaleToFit);
    17.            GUILayout.Space(82);
    18. }
    19.  GUILayout.EndVertical();
    20.  
    21. GUILayout.BeginVertical("Box");
    22. EditorGUILayout.PrefixLabel("Button Sprite");
    23. skinManager.buttonSprite = (Sprite)EditorGUILayout.ObjectField(skinManager.buttonSprite, typeof(Sprite), false);
    24. if (skinManager.buttonSprite != null)
    25. {
    26.           rect = EditorGUILayout.GetControlRect();
    27.           rect = new Rect(rect.x, rect.y - 1, 100, 100);
    28.           EditorGUI.DrawPreviewTexture(rect, skinManager.buttonSprite.texture, null, ScaleMode.ScaleToFit);
    29.           GUILayout.Space(82);
    30. }
    31. GUILayout.EndVertical();
    32.  
    33. GUILayout.EndHorizontal();
    34.