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 McFreezer · Dec 19, 2014 at 10:55 PM · c#guiguistylegui.box

GUI Box with code defined GUIStyle does not show up... What am I doing wrong?

Hey guys, I'm trying to create a GUI output of a BoxTree. Tree works fine. But: I have a function that defines a new GUIStyle based on a preset struct i hooked up to my BoxTree. However, the Draw call is processed OnGUI and nothing shows up. If i use the default style it shows up and everything is fine.

I'm trying to do a simple thing: Draw a Box on a Position with a predefined background color, an image if nedded and text with any related settings.

Here's the definition code:

         public GUIStyle getStyle(Vector2 sc){
             GUIStyle r = new GUIStyle();
 
             Rect br = getRect(sc); //gets a rectangle based on the current screen size (sc)
 
             if(settings.xSize==Size.fix){
                 r.fixedWidth = br.width;
             }
 
             if(settings.ySize==Size.fix){
                 r.fixedHeight = br.height;
             }
 
             if(settings.pad == null) settings.pad = new RectOffset();
             if(settings.margin == null) settings.margin = new RectOffset();
             if(settings.border==null) settings.border = new RectOffset();
 
             r.alignment = getTextAnchor(); //gets preset text anchor
             r.border = settings.border;
 
             r.wordWrap = true;
 
             r.stretchWidth = settings.stretchWidth;
             r.stretchHeight = settings.stretchHeight;
 
             r.font = settings.font;
             r.fontStyle = settings.fontStyle;
             r.fontSize = settings.fontSize;
             //r.lineHeight = r.fontSize + 4;
             r.imagePosition = settings.contentImagePos;
 
             GUIStyleState ss = new GUIStyleState();
             ss.background = settings.bgImage;
             ss.textColor = settings.textColor;
             r.onNormal = ss;
 
             //r.normal.background = settings.bgImage;
             //r.normal.textColor = settings.textColor;
 
             r.onHover = r.onNormal;
 
             r.padding = settings.pad;
             r.margin = settings.margin;
 
             //r.hover.background = settings.bgImageHover;
             //r.hover.textColor = settings.textHoverColor;
             return r;
         }

Is it true that GUI.Box needs to have a background-image? If so, is there a workaround to produce an image based on canvas stuff?

Here's the Draw call: UpdateStyle has been processed before, so "style" is set from getStyle(sc).

         public void Draw(Vector2 sc){
             //style = getStyle(sc); //performance saving, instead: UpdateStyle(Vector2 sc) if needed
             rect = getRect(sc);
 
             GUI.backgroundColor = settings.backgroundColor;
             GUI.contentColor = settings.textColor;
 
             if(useLayout){
                 if(beginLayout)    BeginLayout();
                 else DrawLayout();
             } else
                 DrawNormal();
 
             if(useButtons){
                 if(useLayout){
                     foreach(Box b in buttons){
                         if(GUILayout.Button(
                             b.Content,
                             b.style,
                             new GUILayoutOption[]{
                                 GUILayout.Width(b.rect.size.x),
                                 GUILayout.Height(b.rect.size.y)
                             })){
                             if(OnBtn!=null) OnBtn(this,buttons.IndexOf(b));
                         }
                     }
                 } else {
                     foreach(Box b in buttons){
                         GUI.backgroundColor = b.settings.backgroundColor;
                         GUI.contentColor = b.settings.textColor;
                         if(GUI.Button(b.rect,b.Content,b.style)){
                             if(OnBtn!=null) OnBtn(this,buttons.IndexOf(b));
                         }
                     }
                 }
             }
 
             if(useLayout && endLayout) EndLayout();
         }
Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

2 People are following this question.

avatar image avatar image

Related Questions

Help with GUI class 1 Answer

GUI Style Issue-- Texture not changing 2 Answers

How to Display only current instead of current/max on a GUI.Box 1 Answer

NullreferenceException, BeginScrollView style change 3 Answers

Distribute terrain in zones 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