I want to make a box through the autolayout and punt gui controls in it.
The reference says the following:
Make an auto-layouted box.
This will make a solid box. If you want to make a box with some contents inside, use the style paramenter of one of the subgroup functions (BeginHorizontal, BeginVertical, etc…).
I tried passing BeginVertical as a GuiLayoutoption but unity didnt like it. I also tried the begin vertical before/after the box and the endvertical at finished content, also no good.
Can anyone tell me how i can put controls inside an automatic box?
PS: sorry if this question is already asked but i couldnt find a search function in the forum and there are too much entries to look through.
I did actually read the gui layout multiple times. And also the gui scripting guide. It is just the use of the Guilayout.Box which is confusing.
// Make an area to contain chat
GUILayout.BeginArea(window);
GUILayout.BeginVertical();
// Add box and a space
GUILayout.Box("Chat"); //(new Rect(0, 0, window.width, window.height), "Chat");
// Show screen with chat
GlobalChatWindow();
GUILayout.EndVertical();
// End created area
GUILayout.EndArea();
I want all the controls made in the globalChatwindow function (a scrollview with labels, a textfield and a button) to be INSIDE the box. I commented out the box i previously made with Gui.Box.
I would like to be able to define the controls to go into the box, besides just 1 text you can fit in there.
That is what the manual says on the section. So i tried to use BeginVertical as a layout option which of course failed. Starting beginVertical before or even after the box made the box stop before other controls begin.
My question now is how do i get a scrollview a textfield and a button Inside the Guilayout.box?
You can’t put other controls inside a box created with GUILayout.Box. The GUI elements that can contain other elements are the ones with matching BeginXXX and EndXXX functions (BeginHorizontal, BeginVertical, BeginArea and BeginScrollView.
Okay, i see i was being a bit stupid. I am using a scrollview. I styled the scrollview as a box and it looked fine. I have the look of the box and the controls inside
Since I searched for the same thing and found this thread, I post the answer here. The solution is quite simple:
GUILayout.BeginVertical("MyBox", GUI.skin.box);
GUILayout.Space(20); // spacer to account for the title
// ... your box content ...
GUILayout.EndVertical();