GUI uses 2--to summarize &ngui, TOOKIT2D, GUI comparison

Source: Internet
Author: User

Using the GUI to implement the main code of the form

Using unityengine;using System.collections;public class Mygui:monobehaviour {//public Texture aaa;    public string BBB;    public int CCC;    public string ddd; private bool showwindow;//Controls whether the main form is open private rect windowrectb;//main form private rect btnclose;//Close button public Guiskin    customskin;//Custom Skin Texture Thero;    Public Texture Status1;    Public Texture Status2;    Public Texture Killbox;    private int inttoobar = 0;//is the index number of the selected button.    private int selectiongrid = 0;//is the index number of the selected table button.    Public string[] toobarstring = {"STATUS", "INVENTORY", "equipment"};    Public item[] items; Private Vector2 scrollposition = vector2.zero;//defines the initial position of the scroll bar//public item[]items;   Defines an array of item types//private item CurrentItem;        Use the This for Initializationvoid Start () {ShowWindow = false;        WINDOWRECTB = new Rect (10, 10, 680, 480);        Btnclose = new Rect (620,10,26,22); Items = new Item[2] {New Item (AAA, BBB, CCC, DDD), new Item (AAA, BBB, CCC,DDD)};}        void Update () {if (Input.getkey (KEYCODE.M)) {ShowWindow = true;        }} void Ongui () {Gui.skin = Customskin; if (ShowWindow) {WINDOWRECTB = GUI.            Window (0, WINDOWRECTB, Mydowindow, "", GUI.skin.GetStyle ("WINDOWRECTB")); windowrectb.x = Mathf.clamp (windowrectb.x, 0, screen.width-windowrectb.width);//clamp restriction function, limit the width of the form to 0 and creen.width-        Windowrectb.width between windowrectb.y = Mathf.clamp (windowrectb.y, 0, screen.height-windowrectb.height); }} void Mydowindow (int windowsid) {switch (Inttoobar) {case 0:toolbar                1 ();            Break                Case 1:toolbar2 ();            Break        Case 2:break; } Inttoobar = GUI. Toolbar (New Rect (490, Max), Inttoobar, toobarstring, GUI.skin.GetStyle ("Mytoolbar"));//Draw Toolbar if (GUI. Button (Btnclose, "", GUI.skin.GetStyle("Btnclose")))    Close the form code {ShowWindow = false; } GUI. Dragwindow ();//gui. The Dragwindow () function must be written behind the button code, otherwise there will be a scary thing GUI. Drawtexture (New Rect (19,35,225,441), thero);//display next to the picture} void ToolBar1 () {GUI. Box (new Rect (237, 67, 360, 147), "");//Draw Status box GUI. Box (new Rect (237, 230, 360, 207), "");//Draw the Harvest box GUI.        Drawtexture (New Rect (252, N, 331, a), STATUS1); Gui.        Drawtexture (New Rect (252, 244, 331, a), STATUS2); Gui.        Drawtexture (New Rect (460, 284, 117, a), killbox); Gui.        Label (New Rect (313, 75, 120, 25), "123"); Gui.        Label (New Rect (313, 100, 120, 25), "123"); Gui.        Label (New Rect (313, 124, 120, 25), "123"); Gui.        Label (New Rect (313, 150, 120, 25), "123"); Gui.     Label (New Rect (313, 177, 120, 25), "123");        } void ToolBar2 () {int intitems = 8; Gui.        Box (new Rect (237,67,360,247), ""); Gui.        Box (new Rect (237,330,360,107), ""); scroll bar Section Scrollposition=gui. BeginscRollview (New rect (257,87,320,200), scrollposition,new rect (0,0,280,40*intitems));        guicontent[] itemcontent = new Guicontent[intitems]; for (int i = 0; i < intitems; i++)//{//Selectiongrid = GUI.        Selectiongrid (New Rect (0, 0, 280, intitems), Selectiongrid, itemcontent, 1); } GUI.    Endscrollview (); }}

  

Questions and summaries:

1 new A custom variable in the script, the shared variable in the custom variable cannot be displayed on the Properties panel

(If you want the common fields of your custom classes to appear on the properties panel, you need to inherit Monobehaviour)

2 don't understand the difference between a class and a custom class in unity

3 tookit2d is more convenient to use, but in addition to the method of some trouble (see tookit2d use 3--to add GUI button effect), it is suitable for making 2d games

4 Adding skin components to the GUI can achieve the same effect as Ngui: The distance from each module of the GUI must be controlled by itself, and adding events to the buttons is controlled by using variables, unlike events in C #, (Ngui is equivalent to adding a game object in the game window, While the GUI is only drawn in the Ongui function, the two can achieve the same effect, the principle of implementation is different)

5 This few days of contact with custom classes and learning Network game is quite frustrated, it is unclear the relationship between C # script and Unity script, it is unclear C # delegate, interface, socket, multithreading in unity has no change, looking for work, feel the outcome, neither want to spend too much time to solve a problem, Also feel that there are many do not study.

GUI uses 2--to summarize &ngui, TOOKIT2D, GUI comparison

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.