How To Get A Better Grid Layout in Unity

Поделиться
HTML-код
  • Опубликовано: 19 июн 2024
  • Learn how to build a menu with switchable panels and a flexible grid layout tool in Unity!
    Making UI that Looks Good: • Making UI That Looks G...
    Tab System: • Creating a Custom Tab ...
    Localisation Tool: • Building a Localizatio...
    --------------------------------------------------------------------------------
    Want to support the channel?
    Get the GameDevGuide mug and other merch! ☕ - www.gamedevguide.store
    Use these links to grab some cool assets from the asset store:
    Get the Must Have Assets! - assetstore.unity.com/top-asse...
    Free Unity Assets! - assetstore.unity.com/top-asse...
    New on the Asset Store! - assetstore.unity.com/top-asse...
    Top Paid Asset Store Packages - assetstore.unity.com/top-asse...
    Asset Store Partners - assetstore.unity.com/lists/as...
    --------------------------------------------------------------------------------
    Socials and Other Stuff:
    • Subscribe - ruclips.net/user/gamedevguide?...
    • Join the Discord - / discord
    • Twitter - / gamedevguideyt
    • Facebook - / gamedevguideyt
    • Instagram - / gamedevguideyt

Комментарии • 375

  • @user-fz6zw8uv2r
    @user-fz6zw8uv2r Год назад +18

    This works amazing, thanks man.
    For anyone who can be interested, I modified the for to this so the last one can fill all the empty space:
    float columnCount = 0;
    float rowCount = 0;
    for (int i = 0; i < rectChildren.Count; i++)
    {
    rowCount = i / columns;
    columnCount = i % columns;
    if(fitType == FitType.WIDTH || fitType == FitType.HEIGHT)
    {
    var rest = (rows * columns) - i;
    if (i == rectChildren.Count - 1 && rest > 0)
    {
    cellSize.x *= rest;
    columnCount /= rest;
    }
    }
    var item = rectChildren[i];
    var xPos = (cellSize.x * columnCount) + (spacing.x * columnCount) + padding.left;
    var yPos = (cellSize.y * rowCount) + (spacing.y * rowCount) + padding.top;
    SetChildAlongAxis(item, 0, xPos, cellSize.x);
    SetChildAlongAxis(item, 1, yPos, cellSize.y);
    }
    Also someone write the script and put it on github so yall don't need to pause and copy for the eternity.
    github.com/IkeThermite/GameDevGuide-CustomTabsAndFlexibleGrid/blob/master/Custom%20Tabs%20and%20Flexible%20Grid/Assets/Scripts/FlexibleGridLayout.cs

  • @liormax
    @liormax 4 года назад +366

    is this true? did someone actually made a grid layout tutorial that is actually usefull!?

    • @ben_burnes
      @ben_burnes 4 года назад +32

      Amusingly, by bypassing Unity's grid system and making their own haha

    • @jameshood790
      @jameshood790 4 года назад +30

      Not only that, but it gets right to the point and it's not a series of 27 videos where you watch someone type and debug for hours!

  • @connorking9217
    @connorking9217 4 года назад +188

    For anyone having trouble with spacing causing overflow with more than a 3x3 grid:
    float cellWidth = (parentWidth / (float)columns) - ((spacing.x / (float)columns) * 2)....
    Should be:
    float cellWidth = (parentWidth / (float)columns) - ((spacing.x / (float)columns) * (colums - 1))....
    Same for height.
    Thanks for the great video, keep it up!

    • @bausHuck
      @bausHuck 4 года назад +2

      Thanks. I was wondering this was happening.

    • @timhengeveld
      @timhengeveld 4 года назад +5

      Awesome! This also fixed a problem I was having where a grid with two columns erroneously added spacing to the rightmost and bottommost items in the group

    • @daniellord4174
      @daniellord4174 4 года назад +9

      Not just 3x3, it's all grids. Wandering if OP left this one little flaw to find those blind copy pasta's out there. Best part is OP definitely fixed it before he drags the grid around in the editor.
      new lifegoal: make awesome unity tutorial, leave one blatant flaw. Play unity games looking for ones that made it to production still containing flaw

    • @CorgiCA
      @CorgiCA 4 года назад

      Cheers I was just about to commit to a night of stepping through ✌️😅😇

    • @eliebeaino
      @eliebeaino 3 года назад

      watching this vid half asleep, and i barely understood half of what he said as i'm skimming through it to get a general idea of the system he's done, but when he hard-coded that 2 for the spacing, i was so confused and doubtful. I'm glad to know my confusion was put in the right place. I'm a new unity learner and a new coder, this feels good to know that i'm in the right direction of learning.

  • @motifgaming2080
    @motifgaming2080 4 года назад +35

    Hey, there are very few RUclipsrs who make advanced tutorials so please continue making these videos even when I think I already know everything about the topic I still learn something new from your videos.

  • @thatanimeweirdo
    @thatanimeweirdo 4 года назад +9

    Honestly, it's so refreshing to see someone finally talk about these things. As a UI designer myself, it always seems as these topics just fall flat for most smaller/middle-sized projects.

  • @Andycraft608
    @Andycraft608 4 года назад +1

    I'm so happy I found your channel! There are very very few informative and high quality UI Unity tutorials like yours on the internet. Thank you for sharing the knowledge.

  • @AmanKumar-tu2og
    @AmanKumar-tu2og 4 года назад

    I cannot thank you enough for this. I was totally frustrated by the default grid component, but was too lazy to build an alternative.

  • @r1pfake521
    @r1pfake521 2 года назад +8

    For dynamic or flexible grid I always combine a vertical layout group and filled it with horizontal layout groups for the rows and then every horizontal layout group contains the "cell" elements of the current row. You could also achieve a dynamic grid by using the existing grid layout and update the cell size property in code depending on the total grid width / height. But still nice to how a custom layout group can be implemented and bookmarked for later.

  • @SassyPantsy
    @SassyPantsy Год назад

    This is incredible! Hands down the best tutorial about Unity UI I've ever seen, even general purpose UI implementation. Plus sharing the script itself is very generous of you, it's a must have asset. Subbed&Liked!

  • @TheRealMonkeyCrime
    @TheRealMonkeyCrime 3 года назад +1

    Thanks for making a great series of clear, factual and enjoyable videos. I'd love to see something covering best practices for interfacing your game's logic, variables etc to the UI.

  • @jameshood790
    @jameshood790 4 года назад +3

    I love how you explain what you're doing without making us watch hours of typing and debugging like many other Unity tutorials. Brilliant, right to the point, and right at my level of expertise. Subscribed, and thanks.

  • @ben_burnes
    @ben_burnes 4 года назад

    As someone who usually abhors UI work in Unity, this channel is absolutely brilliant. Thank you for this!

  • @iamjimgroth
    @iamjimgroth 4 года назад

    This is great. I never knew I needed something like this until you mentioned it in the discord the other day. Thanks!

  • @oscar-qr5yy
    @oscar-qr5yy 4 года назад

    I usually don't comment videos. I was already subscribed to you but finding this video looking for a dynamic grid made me activate notifications and comment this.
    THIS IS AWESOME.
    Thank you very much!

  • @aerond8851
    @aerond8851 4 года назад +49

    This channel is so informative and fun to watch at the same time, much more than other Unity tutorial channels I've seen. You definitely deserve more subscribers and attention. Keep it going, your videos are amazing and they help me with my Unity projects, thank you!

    • @MaksMikhnevych
      @MaksMikhnevych 4 года назад +7

      don't hesitate to share the video so the channel will get more subscribers as you wish him so. Apply yourself.

    • @JT_6233
      @JT_6233 9 месяцев назад

      I just wish the "Tab" script used at 2:55 would be somewhere to find.
      I can't find it here in the comments, not in any fan made repository and not in his other videos.
      Not sure how to proceed without this script

  • @llareia
    @llareia 4 года назад

    Thank you SO much for your videos. Unity UI has always been very frustrating for me, and you make it so much easier!

  • @ImSendingXOXO
    @ImSendingXOXO Год назад

    Wow, what an amazing tutorial! So educational, well-made, and perfectly paced. Thank you so much!!

  • @moromann1
    @moromann1 4 года назад

    How have I never seen this channel before?? You have some amazing videos that are very explanatory, concise, and easy to understand. Please continue making videos!

  • @UmeshVerma-pi8oi
    @UmeshVerma-pi8oi 4 года назад

    Thanks for this awesome tutorial, now I am getting some confident and scale UI designs to the next level by programmatically.

  • @shidygames
    @shidygames 3 месяца назад

    This is lit. Thank you for taking the time to show and explain such things, we all agree that the default Grid system is lacking some basic features. Cheers!

  • @Endoo95
    @Endoo95 4 года назад

    Love it! Grids are so important, and your tutorial is so great. Thanks man!

  • @OverAndOverAndOver
    @OverAndOverAndOver 3 года назад

    I LOVE your channel!!! You always have exactly what I need!! I've watched every one of your videos now, and they're all just incredible! You deserve more subscribers, I wish there were more videos to watch!

  • @afrakes4510
    @afrakes4510 2 года назад

    I'm speechless. This is amazing!! Incredible work bro.

  • @RetroGrazer
    @RetroGrazer 8 месяцев назад

    This script saved my butt when trying to make a grid of n x n size. Thank you so much

  • @SnakPak
    @SnakPak 4 года назад

    This is the best Unity tutorial I've ever seen for so many reasons. Instant subscribe

  • @bip901
    @bip901 4 года назад +120

    When picking a font, read the font license VERY carefully to avoid copyright issues. I'm pretty sure Unity embeds fonts into the game, and most font licenses don't allow that.

    • @GameDevGuide
      @GameDevGuide  4 года назад +25

      Great advice! Yeah, licensing popular fonts can be very expensive, but there's also a lot of similar ones that are more affordable. Definitely agree that, like anything, it's worth making sure your usage is covered!

    • @StigDesign
      @StigDesign 4 года назад +8

      @@GameDevGuide use default Comic Sans? :D

    • @heparo8704
      @heparo8704 4 года назад

      Lots of free fonts sites out there 1001Fonts for example my favorite. Edit : free fonts for commercial use, free for personal use etc..

    • @ben_burnes
      @ben_burnes 4 года назад +22

      @@heparo8704 Word of warning: "Free" might mean "Free to use non-commercially". If you intend on selling or distributing your game, do a bit of research beforehand to make sure.

    • @koko0riginal
      @koko0riginal 4 года назад

      A free font that is a suitable replacement recommendation? free as In for commercial use with distribution without modification free

  • @mohitsethi99
    @mohitsethi99 4 года назад

    Really love your channel, every video is so exciting and helpful. Thanks for all the tutorials.

  • @quantumpanic
    @quantumpanic 4 года назад

    Yes! I've always dabbled in trying to customize the grid layout group component because of its potential for functionality (despite being lackluster in what it offers initially). Really hope Unity doesn't overhaul it too much in the future.

  • @TNTCProject
    @TNTCProject 4 года назад

    Super useful Matt! Smooth and clear as always! As the name suggests it is really flexible :D

  • @simoncodrington
    @simoncodrington 4 года назад

    Great content mate, hope to see more UI stuff in the future ❤

  • @CodingWithUnity
    @CodingWithUnity 4 года назад

    Really good video! Deff the best channel for UI/UX related topics by far

  • @TrueIndian
    @TrueIndian 4 года назад

    Informative and in depth tutorial on a specific topic.Thanks.

  • @Shinobi31415926
    @Shinobi31415926 4 года назад +1

    Really useful tutorial. Thank you!!

  • @shazplay8878
    @shazplay8878 4 года назад

    Keep doing tutorials! It's very informative and your code is example of good code for me :)

  • @FerdieSwinkels
    @FerdieSwinkels 4 года назад

    This is an amazing tutorial, nice work!

  • @rutchjohnson
    @rutchjohnson 4 года назад +3

    This is so super helpful!

  • @chrlw
    @chrlw 3 года назад

    Absolute top notch video! Thank you so much!

  • @erdemalpkaya
    @erdemalpkaya 6 месяцев назад

    This is amazing. Thanks for the great work

  • @rmt3589
    @rmt3589 Год назад +1

    Thank you. I think this'll give me most of what I need to make my website simulator!

  • @_denzy_6310
    @_denzy_6310 4 года назад +56

    You go so fast dude! I cannot follow without pausing every second. Also share the scripts where possible. Awesome stuff

  • @christinaVennegerts
    @christinaVennegerts 2 года назад

    Awesome tutorial, thank you very much!

  • @5thBabbitt
    @5thBabbitt 2 года назад

    I found your channel just recently and I love it

  • @artourprice2435
    @artourprice2435 Год назад

    Great Tut. Thank you so much for teaching this.

  • @rahulcorleone4222
    @rahulcorleone4222 2 года назад

    Thanks, It came in handy for my current project.

  • @TheJeffries7
    @TheJeffries7 4 года назад

    I love the venom anytime grid layouts are mentioned.

  • @Tauruspasific
    @Tauruspasific 4 года назад

    I only want to say thanks for all this such amazing job are you doing. ❤️

  • @cradle_of_chaos
    @cradle_of_chaos 3 года назад +2

    This is excellent work.

  • @ArthurDetaille
    @ArthurDetaille 4 года назад

    Every video is even more impressive as the previous one !! :)

  • @homemacai
    @homemacai 3 года назад

    Your videos are awesome mate! Thank you!

  • @alextreme98
    @alextreme98 4 года назад

    you should post more, you are so good dude, i learned a lot from you, thanks 🥇

  • @ObsessiveGames
    @ObsessiveGames 2 года назад

    Great explanation, will use this in one of my future games

  • @osmancanernurdag
    @osmancanernurdag Месяц назад

    This is amazing bro. Thank you :)

  • @SanyaBane
    @SanyaBane 3 года назад

    That's crazy how Unity doesn't have such useful thing out of the box. Thanks a lot!

  • @322ss
    @322ss 4 года назад

    Thanks! This is really neat solution! I've (tried) to create something similar, but it wasn't nearly as clean - and I think I just used grid layout group + script that modified grid child sizes...

  • @OblivionTanks
    @OblivionTanks 4 года назад

    Cool vid. For the project I'm working on I went for a 3D type menu system that navigates like a point and click adventure. Though at first I was using a typical 2d tabbed grid Ui. It was slow and boring to navigate, The 3D menu made things so much more fluid, fast and fun to navigate. If you are going to make a game with lots to do like my project. Might as well make the menus/inventory fun to open up. That the issue I have with lots of AAA games the menus are slow and boring to navigate and for most open world games you spend to much time in them.

  • @clairej3960
    @clairej3960 2 года назад

    fantastic tutorial, thank you

  • @pandaengine
    @pandaengine 4 года назад +1

    Hey man, this is great! I'll definitely use it to design my UI from now on. I already have a half-baked dynamic grid system, but it's only for dynamically initializing an inventory in a scroll rect. I can see that your solution can be easily adapted to that.
    Keep up the good work man! I love your tutorials!

  • @MertKirimgeriGameDev
    @MertKirimgeriGameDev 4 года назад

    Great tutorial! Must-have toolbox item. Thanks :)

  • @szpickij
    @szpickij 4 года назад

    Excellent!
    Keep it up Matt!

  • @aussieraver7182
    @aussieraver7182 2 года назад +1

    You just simplified every future UI pain.
    Flexbox did the same for web development.

  • @adek445
    @adek445 4 года назад

    That looks so cool!

  • @unitypro
    @unitypro 3 года назад

    Loads of thanks for this video

  • @thecookies6109
    @thecookies6109 2 года назад

    Great Found what I was looking for.

  • @richardnorbron4969
    @richardnorbron4969 3 года назад

    Great tutorial. Thanks.

  • @viniciusps01
    @viniciusps01 4 года назад

    All of your vídeos are great. Thank you by that :)

  • @dankenarigato
    @dankenarigato 4 года назад +1

    WOW!!!!! this is very useful .thank you GDG~

  • @allmonty
    @allmonty 3 года назад

    Very nice and useful, thank you :D

  • @CopperFawks
    @CopperFawks 2 года назад

    This helped me a lot today. Thanks ^__^

  • @Knolle3
    @Knolle3 4 года назад +15

    So you are telling me i just found this amazing guy who can code AND explain to me how it is done? No leaving out extra steps. Love it

  • @btiwari-games5279
    @btiwari-games5279 4 года назад

    This is awesome buddy 🤩

  • @samserious5483
    @samserious5483 3 года назад

    Awesome, thank you!

  • @blaiseandthebambina
    @blaiseandthebambina 2 года назад

    I’m an Unreal user all the way but your video was still so dang good and useful. Thank you! Unfortunately now RUclips keeps suggesting Unity videos. Lol :/

  • @MaksMikhnevych
    @MaksMikhnevych 4 года назад

    Damn, king, what a great approach!

  • @farfi55
    @farfi55 4 года назад

    Great content as usual 👍

  • @rubyrails2329
    @rubyrails2329 4 года назад

    The best channel for unity tutoral with Brackeys

  • @Sergalt
    @Sergalt 4 года назад

    That is really nice and informative tutorial

  • @xxx.xxx.xxx.xx1joker706
    @xxx.xxx.xxx.xx1joker706 4 года назад

    Excellent. Many thanks.

  • @-vhs
    @-vhs 4 года назад

    I am in love with your channel!

  • @ahmedradwan5385
    @ahmedradwan5385 4 года назад

    one of the best channels ever

  • @admulberg
    @admulberg 4 года назад +1

    Hi! For enabling/disabling you can just do: panels[i].gameObject.setActive(i == panelIndex); instead of using if/else

  • @kken8766
    @kken8766 4 года назад

    this video is very helpful. u r awesome. I wish your channel has more videos to watch.

  • @Pedro_Marangon
    @Pedro_Marangon 4 года назад +2

    I've been waiting for this video for a long time!

  • @haos4574
    @haos4574 Год назад

    great tutorial, exactly what I am looking for. I wonder if you have plans to add a scrollview to the custom grid layout, which would be extremely useful.

  • @neves188
    @neves188 3 года назад

    THANK YOU SO MUCH!!!

  • @TYNEPUNK
    @TYNEPUNK 3 года назад

    Very good video thank you very much

  • @danthesandman
    @danthesandman 4 года назад +4

    It felt a little cathartic when you took a jab at the grid layout in the last video. After seeing that in this video as a UI/UX person I had to sub. One question though: Does this Flexible grid work with a content size fitter?

  • @techmaster9041
    @techmaster9041 3 года назад

    OMG there is someone better than Brackeys. U R My new FAVOURITE RUclipsR!!!!!

  • @akaHarvesteR
    @akaHarvesteR 3 года назад

    Brilliant work! UI work in unity is always such a pain IMO. I've been doing it for ten years and I still struggle with those damn layout group components. I will definitely give yours a try.
    Also thank you for implementing padding using floats!! (Ever notice that unity's use integers?)

  • @urselhorst9253
    @urselhorst9253 Год назад

    i love this. your awesome!

  • @HausCoding
    @HausCoding 3 года назад +1

    my hero!

  • @gamerzshare550
    @gamerzshare550 4 года назад +1

    Simply awesome. Sourcecode will be great.

    • @mahna_mahna
      @mahna_mahna 3 года назад

      Another coder has made this from the videos:
      github.com/IkeThermite/GameDevGuide-CustomTabsAndFlexibleGrid

  • @FearlessNite345
    @FearlessNite345 3 года назад

    I would love to see a video on how to make those buttons and how to outline them like you did

  • @heparo8704
    @heparo8704 4 года назад

    It reminds me of java's good old GridBagLayout... ^^. Good job !

  • @The4ININ
    @The4ININ 4 года назад

    Thank you for amazing videos!
    Want to know in your next video or comment :
    1. How to make group TMPro text with same font size when resolution change?
    2. How to set unity scene build resolution setup (for example : between aspect ratio 2: 1 and 1:1)?

  • @scorpion666lair
    @scorpion666lair 4 года назад

    This is brilliant! Thanks for sharing, I'll definitely be implementing this 😊

  • @umadkuzubad
    @umadkuzubad 2 года назад

    Can't thank you enough!

  • @RickMcMichael
    @RickMcMichael 3 года назад +2

    Great videos, my only complaint is not being able to see what components are on the parent objects before you get started. Also did I miss the creation of the "Tab" Script? - I saw TabGroup and TabButton. Assuming you made one off camera? Maybe one day you could do some tutorials for World Space canvas scripts xD

  • @andrewm4815
    @andrewm4815 3 года назад

    Great video.

  • @elzar8763
    @elzar8763 Год назад

    thank you

  • @TheMonyarm
    @TheMonyarm 4 года назад

    I would love it if you could make a vud on crating Fallout/Skyui esque list inventories, with a 3d preview.