Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 /
avatar image
1
Question by lancer · Aug 13, 2013 at 03:37 AM · javascriptguishopkeeper

Setting Scroll View Width GUILayout

What I need fixed is that when the buttons exceeds the scroll view width it starts scrolling horizontally, like so:

alt text

But what I want it to do is start drawing the buttons down 1 and then horizontal again so the horizontal scroll view is never changed just the vertical and I have a nice block of buttons like in this image I photoshoped:

alt text

I have this script:

 #pragma strict
 
 var ShopName : String;
 
 var Enabled : boolean;
 var BackgroundTexture : Texture;
 var Items : String[];
 var ItemTextures : Texture[];
 
 private var shopSize : Rect = Rect(Screen.width / 2,0,600,800);
 
 private var scrollPosition : Vector2;
 
 private var currentButton : int;
 
 function Start () {
     shopSize = Rect(Screen.width / 2 - 300,0,600,Screen.height);
 }
 
 function Update () {
 
 }
 
 function OnInspectorUpdate(){
     
 }
 
 function enable(i : boolean){
     if(i == true){
         Enabled = true;
     }
     if(i == false){
         Enabled = false;
     }
 }
 
 function OnGUI(){
     if(Enabled == true){
         shopSize = GUILayout.Window(200, shopSize, ShopWin, ShopName);
     }
 }
 
 function ShopWin (windowID : int) {
 
     scrollPosition = GUILayout.BeginScrollView (scrollPosition, false, true, GUILayout.Width(600),GUILayout.Height(Screen.height - 100));
 
     GUILayout.BeginHorizontal();
     //if(currentButton == 0)
     for(var i:int =0;i<Items.length;i++){
         if(ItemTextures.Length > 0){
             if(GUILayout.Button(ItemTextures[i], GUILayout.Width(60), GUILayout.Height(60)))
             {
             
             }
         }
         else{
             if(GUILayout.Button(Items[i].ToString(), GUILayout.Width(60), GUILayout.Height(60)))
             {
         
             }
         }
         //currentButton = currentButton + 1;
     }
     
     GUILayout.EndHorizontal();
     GUI.DragWindow();
     GUILayout.EndScrollView();
 }
2.png (107.0 kB)
2phed.png (120.2 kB)
Comment
Add comment · Show 6
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 lancer · Aug 13, 2013 at 02:25 PM 0
Share

does anyone know what I have do?

avatar image Pivius · Aug 13, 2013 at 02:43 PM 0
Share

You need GUILayout.BeginVertical() and GUILayout.EndVertical(); Somewhere Outside the loop.

Im not really good at javascripting so unfortunately i cant help out that much

avatar image lancer · Aug 13, 2013 at 02:59 PM 0
Share

I know that much, but don't know where to put them to make it work.

avatar image lancer · Aug 13, 2013 at 03:21 PM 0
Share

I'll need a version of this script that works the way I want within the next few days for an unity add-on I'm writing.

avatar image tw1st3d · Aug 13, 2013 at 03:33 PM 0
Share

Sounds like you should start figuring it out then.

Show more comments

1 Reply

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

Answer by numberkruncher · Aug 14, 2013 at 01:30 AM

To render a grid of buttons you could do something like the following to separate the buttons into separate rows. I have not tested the following, but you should see the general idea:

 function ShopWin(windowID:int) {
     scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, true, GUILayout.Width(600), GUILayout.Height(Screen.height - 100));
     
     GUILayout.BeginHorizontal();
     
     // You might want to calculate this value, but for example
     // purposes I'll just hard wire 9.
     var buttonColumnCount:int = 9;
     
     for(var i:int = 0; i < Items.length; ++i) {
         // Begin new row?
         if (i % buttonColumnCount == 0 && i > 0) {
             GUILayout.EndHorizontal();
             GUILayout.BeginHorizontal();
         }
 
         if(ItemTextures.Length > 0){
             if(GUILayout.Button(ItemTextures[i], GUILayout.Width(60), GUILayout.Height(60)))
             {
 
             }
         }
         else{
             if(GUILayout.Button(Items[i].ToString(), GUILayout.Width(60), GUILayout.Height(60)))
             {
 
             }
         }
     }
  
     GUILayout.EndHorizontal();
     GUI.DragWindow();
     GUILayout.EndScrollView();
 }
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

18 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

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Arrange ints from biggest to smallest and display them in a table 1 Answer

How to access a non static variable by another static variable? 1 Answer

Temperature Script? 3 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