C # Writing a dynamic window of Unity basic Gui

Source: Internet
Author: User

1. Create a window

1 // declare window position size 2 Private rect Pos = new rect (,); 3 4 // callback function 5 void wincallback (int id) 6 {7 if (GUI. button (New rect (,), "button in the window") {8 print ("button clicked in the window "); 9} 10} 11 12 Void ongui () 13 {14 Pos = GUI. window (0, POs, wincallback, "my window"); 15}

Effect;

 

Define a window that can be moved with the mouse:

Add in the callback function

1 void wincallback (int id) 2 {3 if (GUI. button (New rect (,), "button in window") {4 print ("button clicked in window"); 5} 6 7 GUI. dragwindow (); 8}

Note that you need to put this function at the end of the callback function;

If you use

GUI.DragWindow(new Rect(0,0,100,50));

It will limit the area that can be dragged (I tested it, but the effect is not very good );

 

Use the switch to control whether the display window is displayed or not:

1 private rect Pos = new rect (,); 2 3 // callback function 4 void wincallback (int id) 5 {6 if (GUI. button (New rect (,), "button in the window") {7 print ("button clicked in the window"); 8} 9 10 GUI. dragwindow (New rect (,); 11} 12 13 private bool showwin = true; 14 15 void ongui () 16 {17 showwin = GUI. toggle (New rect (,), showwin, "display window"); 18 19 if (showwin) 20 {21 Pos = GUI. window (0, POs, wincallback, "my window"); 22} 23}

Effect:

C # Writing a dynamic window of Unity basic Gui

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.