- Home /
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();
}
Your answer
Follow this Question
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