[Original] unity3d deep dive-Gui Control

Source: Internet
Author: User

The GUI class of Unity provides a variety of interface controls. By combining these controls, you can complete the interface for user interaction.

  • Lable: Draw text and images
  • Box: Draw a graphic box
  • Button: Draw a response to click the event button
  • Repeatbutton: draws a button to process consecutive events.
  • Textfield: draws a single line text input box
  • Passwordfield: draws a password input box.
  • Textarea: draws a multi-line text input box
  • Togle: Draw a switch
  • Toolbar: Draw a toolbar
  • Selectiongrid: Draw a set of grid buttons
  • Horizontalslider: Draw a horizontal slide
  • Verticalslider: Draw a Vertical Slide
  • Horizontalscrollbar: draws a horizontal scroll bar.
  • Verticalscrollbar: draws a vertical scroll bar.
  • Window: draws a window that can be used to place controls.

Gui code can be drawn only when it is called in the ongui function. If it is placed in the update function, an error is reported.

A rect parameter is required for the GUI control to specify the drawing area of the screen. For example, rect (100, 60) is drawn at the coordinates (20, 40) in the upper left corner of the screen, with a width of and a height of 60.

Note: In the unitygui, the screen coordinate system uses the upper-left corner as the origin (), and the lower-right corner as the screen. widht, screen. Height)

 

Guilayout Automatic Layout:

In unity, there are two GUI controls: one is fixed layout, that is, the location parameter passed in when the control is drawn; the other is guilayout automatic layout, this method is generally used when developers do not care much about the precise position of controls.

If you want to use automatic layout, use guilayout to draw the control.

Example:

Void ongui () {// fixed layout GUI. button (rect (20, 40,), "Gui button"); // automatically layout guilayout. button ("I am an automatic IC layout button ")}

 

Area:

Sometimes Automatic Layout is used. When the number of controls is too large, it will appear too messy. In this case, you can use guilayout. beginarea and guilayout. endarea is used to specify the area to be placed in the Automatic Layout. The display area is roughly divided.

Example:

Void ongui () {guilayout. beginarea (New rect (screen. width/2, screen. Height/2,200,200); // draw the control guilayout. endarea ();}

There are also guilayer. beginhorizontal and guilayer. endhorizontal to set the horizontal layout.

Guilayout. beginvertical and guilayer. endvertical, class set vertical layout.

[Original] unity3d deep dive-Gui 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.