Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Scaling GUILayout selection grid content without changing size of selection window

Discussion in 'Immediate Mode GUI (IMGUI)' started by Spartiate0033, Apr 22, 2017.

  1. Spartiate0033

    Spartiate0033

    Joined:
    Dec 23, 2014
    Posts:
    11
    Hello Unity community,

    I created a custom editor window and used GUILayout.SelectionGrid to make my own selection grid using textures. I was able to get my own prefabs showing and get it to scale based off the window size. However, all of the elements in the selection grid are huge. The problem is that when I set a max height/width, the size of the grid also changes regardless of the grid count.

    Code (CSharp):
    1.  GUILayout.BeginVertical("Box");
    2. m_Selection = GUILayout.SelectionGrid(m_Selection, texContainer.ToArray(), itemsPerRow,
    3.      GUILayout.MaxHeight((int)this.position.height), GUILayout.MaxWidth((int)this.position.width)
    4.      /*GUILayout.ExpandHeight(false), GUILayout.ExpandWidth(false)*/);
    5. GUILayout.EndVertical();
    I have tried it with and without expanding the height, and that did not help.

    My question is, how can I achieve the effect of the grid but allow my objects to scale to any size while having the area the content is in the size of the editor window.

    Thank you.

    USING THE SIZE OF THE CUSTOM EDITOR WINDOW:

    Img.png

    USING A GENERIC SIZE:

    Img2.png