A control group can be viewed as a large container, a control within a control group that has a relative position that is the base of the control group, and no longer the upper-left corner of the screen.
Here's a look at the code examples and their effects:
public class Gui2:monobehaviour {int toolbarint=0;//represents the default N-1 button is active string[] toolbarstring={"Tools", "Forms", "Help"};// Number of button names and set int selectgrid=0;string[] selectgridsring = {"Grid 1", "Grid 2", "Grid 3", "Grid 4", "Grid 5"};//use the "this for Initia" Lizationvoid Start () {}//Update is called once per framevoid update () {}void Ongui () {Guilayout.button ("This is a GUI button"); GUI . BeginGroup (New Rect (screen.width/2-50, SCREEN.HEIGHT/2-50, N)); toolbarint = GUI. Toolbar (New Rect (0, 0, up, max), Toolbarint, toolbarstring); Selectgrid = GUI. Selectiongrid (New Rect, Selectgrid, selectgridsring, 2),//2 columns, unity can automatically scale//detect if the control has changed if (gui.changed {print ("Some controls have changed");//The specific control click Change if (toolbarint==1) {print ("toolbar1 was clicked");}} Gui. Endgroup ();}}
Gui. Endgroup (); Is the end distance of his nearest gui.begingroup ();
Below we can take advantage of the nesting of control groups to achieve some special effects, such as the video loading buffer bar ~
The specific code is as follows:
Public classNextgroup:monobehaviour { Publictexture2d bgimg; Public floatplay=1.0f; //Use this for initialization voidStart () {}//Update is called once per frame voidUpdate () {Play-=0.002f; if(Play <=0f) {Play=1f; } } voidOngui () {GUI. BeginGroup (NewRect (0,0, the, +)); Gui. Box (NewRect (0,0, the, +), bgimg); Gui. BeginGroup (NewRect (0,0, Play * the, +)); Gui. Box (NewRect (0,0, the, +),""); Gui. Endgroup (); Gui. Endgroup (); }}
There are 2 groups of controls nested here, and then the size of the box inside each frame changes to achieve the effect we want.
Learn Unity3d from scratch (GUI Chapter Group view Control)