Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by modernator24 · Aug 29, 2018 at 10:23 AM · uiguieditor-scriptinglayoutguilayout

How to make Grid Layout Buttons in Custom Editor Window?

I'm trying to making custom window UI something like this:

alt text

However there's no such grid feature in Unity's GUI API. I tried with GUILayout.FlexibleSpace for each column, but it didn't worked.

I just can't understand, why Unity made API so complicated and hard to implement such a simple interface? I still get confusing which API to use: GUILayout, EditorGUILayout, EditorGUI.

Even drawing a simple image is not simple :(

Anyway how do I make code for display buttons like my concept art? Any advice will very appreciate it.

goal.png (2.7 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image eses · Aug 30, 2018 at 07:31 AM 0
Share

@modernator24 - Hi, I added an answer for editor GUI layout - see if it helps, or not.

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by tcz8 · Apr 12, 2019 at 05:34 PM

No need to reinvent the wheel.

Please see: GUILayout.SelectionGrid

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image avvie · Jul 29, 2020 at 08:28 AM 0
Share

That doesnt really work. it just lets you know what was the last one that was clicked. So you can know about something being clicked if the index changes. If you need to detect multiple clicks on the same button consecutively it wont help

avatar image TribalInstincts avvie · Mar 21 at 10:58 PM 0
Share

Old, but for future readers, you can use this like buttons by having the value set as -1 at the on each draw then grabbing the change:

 string[] options = new[] {"UL", "UC", "UR", "CL", "CC", "CR", "BL", "BC", "BR"};
 int selected = GUILayout.SelectionGrid(-1, options, 3);
 if (selected > -1)
 {
     Debug.Log("Selected: " + options[selected]);    
 }

avatar image
1

Answer by eses · Aug 29, 2018 at 10:33 AM

@modernator24

How about something like this?

 void OnGUI () 
 {
     GUI.BeginGroup (new Rect (Screen.width * 0.5f, Screen.height * 0.5f, 400, 400));
 
     GUI.Box (new Rect (0,0,230,230), "Directions");

     
     var off = 20f;
     var px = 20f;
     var py = 20f;

     GUI.Button (new Rect (50+px+off,0+off,50,50), "1");


     GUI.Button (new Rect (0+off,50+py+off,50,50), "2");

     GUI.Button (new Rect (50+px+off,50+py+off,50,50), "3");

     GUI.Button (new Rect (100+px*2f+off,50+py+off,50,50), "4");


     GUI.Button (new Rect (50+px+off,100+py*2+off,50,50), "5");

     GUI.EndGroup ();
 }



alt text


GUI.* elements are placed manually (have to use when doing property drawers at least IIRC). GUILayout then again, is not fixed size.

I think in general, just use GUILayout, it is basically auto layout, whereas GUI forces you to manage placements and rects.

First and last line have empty / dummy buttons to make layout work.
Here's There are probably better ways to do the whole layout, (both first and second example), but this is what I've used. In this case, it is made to scale down, but not up:

 void OnGUI () 
 {
     skin = GUI.skin;
 
     GUILayout.BeginHorizontal();
     
     GUILayout.Button("", skin.label, GUILayout.ExpandWidth(false),GUILayout.MaxHeight(50f), GUILayout.MaxWidth(50f));
     GUILayout.Button("1", GUILayout.ExpandWidth(false),GUILayout.MaxHeight(50f), GUILayout.MaxWidth(50f));
     GUILayout.Button("", skin.label, GUILayout.ExpandWidth(false),GUILayout.MaxHeight(50f), GUILayout.MaxWidth(50f));
 
     GUILayout.EndHorizontal();
 
     GUILayout.BeginHorizontal();
     GUILayout.Button("2", GUILayout.ExpandWidth(false),GUILayout.MaxHeight(50f), GUILayout.MaxWidth(50f));
     GUILayout.Button("3", GUILayout.ExpandWidth(false),GUILayout.MaxHeight(50f), GUILayout.MaxWidth(50f));
     GUILayout.Button("4", GUILayout.ExpandWidth(false),GUILayout.MaxHeight(50f), GUILayout.MaxWidth(50f));
     GUILayout.EndHorizontal();
 
     GUILayout.BeginHorizontal();
     
     GUILayout.Button("", skin.label, GUILayout.ExpandWidth(false),GUILayout.MaxHeight(50f), GUILayout.MaxWidth(50f));
     GUILayout.Button("5", GUILayout.ExpandWidth(false),GUILayout.MaxHeight(50f), GUILayout.MaxWidth(50f));
     GUILayout.Button("", skin.label, GUILayout.ExpandWidth(false),GUILayout.MaxHeight(50f), GUILayout.MaxWidth(50f));
 
     GUILayout.EndHorizontal();
 }


Result:

alt text




20189829-recttransform-cross-2.png (10.0 kB)
20189829-buttons-cross-autolayout.png (5.7 kB)
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image modernator24 · Aug 29, 2018 at 10:42 AM 0
Share

No, I'm not talking about UGUI. I'm talking about making UI for Custom Editor Window.

avatar image eses modernator24 · Aug 29, 2018 at 12:19 PM 0
Share

@modernator24 - oh, ok I edited my answer - was too sleepy I guess.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

280 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to set sorting order of UI elements, when Sorting Group doesn't work? 2 Answers

New GUI - Order of elements? 0 Answers

Why is this List only showing one int? 0 Answers

UnityEvents for UI updating, generic way of removing repeated calls in same frame. 0 Answers

Attach UI elements to screen corners 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges