Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Drag And Drop Puzzle Game withy Dynamic Sizes (GRID LAYOUT)!

Discussion in 'Scripting' started by hikariakio, Aug 18, 2020.

  1. hikariakio

    hikariakio

    Joined:
    Dec 19, 2016
    Posts:
    25
    Hello, I am planning to make an educational game and I have encountered with kind of this task. For UI Layout, I want the child to dynamically scale (only width) with content inside. But default UI "Grid Layout" does not allow me to do such so( It requires all children to be in fixed width and height , which I do not want) .

    I've thought a way of making with Multiple Horizontal Groups and Vertical Groups (with some calculation) Screen Shot 2020-08-18 at 12.32.58.png but those data are coming from backend API so, I have no control or what so ever.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,345
  3. hikariakio

    hikariakio

    Joined:
    Dec 19, 2016
    Posts:
    25
    But Grid Layout needs all children to be in the constant size, doesnt it? In this way, content size fitter cannot help me.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,345
    Grid does yes, but Horizontal layout and Vertical Layout don't have this restriction.

    The picture you show could probably be redone with:

    Canvas
    -VertLayout
    --HorizLayout1
    ---Item1
    ---Item2
    ---Item3
    --HorizLayout2
    ---Item4
    ---Item5
    ---Item6
    ---Item7


    Size fitters would be on the items, and I suppose on the horiz layouts too, if they are varying heights.

    I advise you work this up slowly, no code, just lay it out in the scene and understand how it has to be put together... it can be a little fiddly-widdly to get it right. :)