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 Kallen330 · Feb 08, 2014 at 12:26 AM · sizeheighticonguistyleguicontent

How do I get the GUI Icon to stretch?

Okay, searched everywhere and still haven't gotten a good answer. I want the cards to be the texture of the button, and despite the fact that the container is a long rectangle, I can't get the guicontent image to scale to anything that's not square. Works great for square icons, but I need these cards to be card shaped.

alt text

I've really searched everywhere. Any help?

68c63e34bb28e4ff730da5111b1d657c.jpg (391.6 kB)
Comment
Add comment · Show 4
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 getyour411 · Feb 08, 2014 at 05:40 AM 0
Share

post the code you are using to display these and if you are using a guiskin, the relevant details like fixed width/height/stretech/etc (screenshot be best)

avatar image supernat · Feb 08, 2014 at 07:04 AM 0
Share

I'm not familiar with GUIContent, but it seems fairly limited. Try playing with the GUITexture and GUITexture.pixelInset value ins$$anonymous$$d.

avatar image Kallen330 · Feb 08, 2014 at 09:14 AM 0
Share

The code is a little convoluted, but I'm using a matrix to resize everything and a GUIskin with its own styles (with fixed height and width set to 0 currently, because they were a headache)

     void OnGUI() {
         GUI.skin = my_skin;
         scale.x = (float)Screen.width/1980.0f;
         scale.y = (float)Screen.height/1080.0f;
         scale.z = 1;
         
         var sv$$anonymous$$at = GUI.matrix;
         GUI.matrix = $$anonymous$$atrix4x4.TRS(Vector3.zero, Quaternion.identity, scale);
         
         if(Event.current.type == EventType.Layout && Event.current.clickCount == 0) 
              GUI.matrix = $$anonymous$$atrix4x4.identity;
         
         if(display_inventory){
             inv_window_rect = GUI.Window(INV_WINDOW_ID, inv_window_rect, InventoryWindow, "", "$$anonymous$$enu Background");
         }
         DisplayToolTip();
         
         GUI.matrix = sv$$anonymous$$at;
     }
     
     public void InventoryWindow(int id){
         GUI.skin = my_skin;
         
         int counter = 0;
         GUI.Box(new Rect(580,250,620,550), "", "Inventory Background");
         for(int y = 0; y < inventory_rows; y++){
             for(int x = 0; x < inventory_cols; x++){
                 if(counter < PlayerScript.Inventory.Count){    
                     GUI.Button (new Rect(411 + (x * button_width + (x*1.5f)), 285 + (y * button_height + (y*5)), button_width, button_height), new GUIContent(PlayerScript.Inventory[counter].material.mainTexture /*PlayerScript.Inventory[counter].ToolTip(PlayerScript.Inventory[counter])*/));
                 } else {
                 counter++;
             }
         }
         SetToolTip();
         GUI.DragWindow();
     }
avatar image getyour411 · Feb 08, 2014 at 09:37 AM 0
Share

I think that 'headache' has to be tackled again. You need a GUIStyle to tell your GUIContent how to render and using fixedHeight and fixedWidth to shape the image as you need it, or trying Stretch/true to see if GUI.Button does it automatically) looks to me, from the docs, as the way to do this,.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Kallen330 · Feb 08, 2014 at 06:20 PM

I was able to solve my problem, it seems. I had to redo the matrix a bit to get the gui elements to scale correctly, and redo the shape of the buttons somewhat to get the proper proportion. The GUI button fixed height will resize it, but it's always proportional, which is a pain, so the proportion has to be correct in the first place.

alt text


a5b791cd2d19491c56684255b861690c.jpg (366.4 kB)
Comment
Add comment · Show 1 · 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 getyour411 · Feb 08, 2014 at 06:21 PM 0
Share

nice job, looks great

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

19 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

Related Questions

Get GUI size 1 Answer

EditorGUILayout size not calculated automatically? 1 Answer

Cutoff top and bottom of screen instead of sides when changing aspect ratio 1 Answer

Custom Icons for EditorGUIUtility.IconContent 1 Answer

Having an issue with setting the minimum size for a field size 0 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