Learn Unity3d from scratch (GUI Chapter Group view Control)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.