Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by Aequitas · Aug 23, 2010 at 04:13 PM · guibuttonpositioninfinite

Infinite GUI Button positions.

Basically I'm pulling data off a database and displaying said information if you click on buttons. However there is an infinite number of objects that are stored inside this database. I know how to position objects in a GUI if there are a finite number of them, but how would I achieve something like this with an infinite number of them? How could I set the X and Y positions for each new button?

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 qJake · Aug 23, 2010 at 10:49 PM 1
Share

You should probably use a scrollview.

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Aequitas · Sep 08, 2010 at 07:26 AM

There was quite a simple solution to this one, just using a for loop, and incrementing the X and Y dimension variables. I thought it would effect all the buttons in the loop, but I was wrong.

Comment
Add comment · 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
0

Answer by DaveA · Aug 24, 2010 at 05:40 AM

Scrollview as SpikeX said, but if there is really a LOT of them, it may be too many for one list. Can you structure the number of objects to choose from with some criteria to shorten the list? For example 'Starting with the letter A' or 'the shortest ones' or some other way of dividing up the list? Thus you might have 2 or more UI objects (say, one scrollview for 'narrow the search' and another for 'pick from those found').

Data visualization is a big field of study, worth googling. I've found that making hierarchies (trees, for example) that hide/show their children works pretty well. Then you can make them 'share the screen' by not all being on screen at the same time.

Comment
Add comment · Show 3 · 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 Aequitas · Aug 25, 2010 at 08:44 AM 0
Share

I'm already using Scrollview. $$anonymous$$y questions wasn't relating to that however. I'm talking about giving each button a new width in the window, otherwise they will all display on top of each other after the for loop has finished.

avatar image DaveA · Aug 25, 2010 at 07:30 PM 0
Share

GUI.Button can take a Rect as the placement (left,top,width,height), so if you want to lay them out as a 2D grid, decide the aspect ratio (how many rows/columns, for square it would be sqrt(count_of_items) roughly) then divide the available screen by number of rows and columns, that will give width & height. You'll need to pad for margins and general good-looking-ness. OnGUI() executes a lot, so you can change those size/positions any time and they will re-layout for you.

avatar image spinaljack · Sep 07, 2010 at 12:51 PM 1
Share

Just use GUILayout.Box ins$$anonymous$$d of GUI.Box, that will automatically position each item in its own row without a Rect

avatar image
0

Answer by james flowerdew · Sep 07, 2010 at 12:39 PM

I think I know what you want, and the answer is to use maths to set the coordinates of the button instead of hard and fast values. a "for" loop with incrementing numbers is our chosen method, as long as the list doesn't get too big, the code below takes an array of string choices called pchoices (set elsewhere) and builds buttons on incrementing coordinates. I use the "vButChosen" Variable to execute the button action in an update.

int vMakeRoom=20;
int vButHeight=Screen.height/15;
int vButWidth=(int)(vButHeight*6.1f);
int vButPadding = vButHeight/5;
int vButPlaceX=Screen.width-vButWidth-vButPadding;
int vButPlaceY=Screen.height-(pChoices.Length*(vButHeight+vButPadding));
Rect vLoc;
vButChosen="Null";
for (int vBut=0;vBut<pChoices.Length;vBut++){
         vLoc=new Rect(vButPlaceX,vButPlaceY+vBut*(vButHeight+vButPadding),vButWidth,vButHeight);
    if(GUI.Button(vLoc,pChoices[vBut])){
        vButChosen=pChoices[vBut];
    }
}
}

I know that this is a bit long winded, but does it help?

Cheers,

James

Comment
Add comment · 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

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

No one has followed this question yet.

Related Questions

GUI positioning 1 Answer

Change GUI button position in code 1 Answer

GUI Button and a gameObject's position 3 Answers

Question about positioning GUI. 1 Answer

Button position 4 Answers


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