GUI入門

歡迎來到unity學習unity培訓
這裏有很多U3D資源U3D培訓視頻、U3D教程、U3D常見問題、U3D項目源碼,我們致力於打造業內unity3d培訓、學習第一品牌

1、Label


    void OnGUI() {


    //static function Label (position : Recttext : string) : void

    E.g:  GUI.Label(Rect(10, 10, 100, 20), "Hello World!");


    //static function Label (position : Rectimage : Texture) : void

    E.g:   GUI.Label(new Rect (20,50,img.width ,img.height),img);


    //static function Label (position : Rectcontent : GUIContent) : void

    E.g: GUI.Label(new Rect(10, 80, 150, 20), new GUIContent("請點這裏", "content "));

    GUI.Label(new Rect(130, 40, 150, 40), GUI.tooltip);


    //static function Label (position : Recttext : string, style : GUIStyle) : void   

    和第一個相差不多,就是多加了個style限制字數。

    E.g GUI.Label(new Rect(10, 10, 100, 20), "Hello World!",style:"3");

    }


2、Box、Button和Label用法差不噢多,就是Botton是一個按鈕,Label是個文本格式,Box是個盒子


3、RepeatButton和Button基本一樣,Botton是點擊一下的控件,而RepeatButton是雙擊的控件


4、TextField:文本字段


    能夠往裏面輸入和消除文本,而且這個減少了圖片和觸碰效果,增加了限制字數

    //static function TextField (position : Recttext : StringmaxLength : int) : String


    E.g public string stringToEdit = "Hello World";

        void OnGUI()

        {

            stringToEdit = GUI.TextField(new Rect(10, 10, 200, 20), stringToEdit, 25);

        }

5、PasswordField:密碼字段


    PasswordField (position : Rect, password : String, maskChar : char) : String

    PasswordField (position : Rect, password : String, maskChar : char, maxLength : int) : String

    PasswordField (position : Rect, password : String, maskChar : char, style : GUIStyle) : String

    PasswordField (position : Rect, password : String, maskChar : char, maxLength : int, style : GUIStyle) : String


    注:String:maskChar----用於密碼的字符遮罩。


    E.g public string stringToEdit = "Hello World";

    void OnGUI()

    {

        stringToEdit = GUI.PasswordField(new Rect(10, 10, 200, 20), stringToEdit, "*"[0], 25);

    }

    文本可消除


6、TextArea:文本區域


用法和TextField用法差不多,就是可以輸入多行


E.g public string stringToEdit = "Hello World\nI've got 2 lines...";

    void OnGUI()

    {

        stringToEdit = GUI.TextArea(new Rect(10, 10, 200, 100), stringToEdit, 200);

    }

發佈了50 篇原創文章 · 獲贊 5 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章