GUI 控制項學習一(C#)

來源:互聯網
上載者:User

標籤:style   blog   http   color   os   width   

程式碼片段:

using UnityEngine;using System.Collections;public class SkinTest : MonoBehaviour {    public Texture imgbtn;    private string textContent ="Textfield";    private string passwordToEdit ="PasswordField";    private string textAreaToEdit = "Hello world \n I‘m textArea";    public Texture toggleImgTexture;    private bool toggleTxt;    private bool toggleImg;    private int toolInt =0;    private string[] toolNameArr={"Toolbar1","Toolbar2","Toolbar3"};    private float hSlideValue=0;    private float vSlideValue=0;    private float hSbarValue;    private float vSbarValue;    private Vector2 scrollPosition = Vector2.zero;    private Rect windowbox = new Rect(400,250,220,100);    // Use this for initialization    void Start () {            }        // Update is called once per frame    void Update () {        }    void OnGUI (){        //Label控制項        GUI.Label (new Rect(10,10,100,20),"Label");        //Button控制項        if(GUI.Button (new Rect(10,30,100,20),"Button")){            print("按下Button按鈕.");        }        if(imgbtn){            if(GUI.Button (new Rect(10,60,imgbtn.width,imgbtn.height),imgbtn)){                print("按片按鈕.");            }        }        //RepeatButton控制項        if(GUI.RepeatButton(new Rect(10,130,100,20),"RepeatButton")){            print("按下RepeatButton按鈕.");        }        //TextField控制項        textContent = GUI.TextField (new Rect(10,160,120,20),textContent);        //PasswordField控制項        passwordToEdit = GUI.PasswordField (new Rect(10,190,120,20),passwordToEdit,"*"[0],25);        //textArea控制項        textAreaToEdit = GUI.TextArea (new Rect(10,220,120,100),textAreaToEdit);        //Toggle控制項        toggleTxt = GUI.Toggle (new Rect(10,350,100,20),toggleTxt,"   toggle text");        if(toggleImgTexture){            toggleImg= GUI.Toggle (new Rect(10,380,50,50),toggleImg,toggleImgTexture);        }        //ToolBar控制項        toolInt = GUI.Toolbar (new Rect(10,430,200,30),toolInt,toolNameArr);        //Slide控制項        hSlideValue = GUI.HorizontalSlider(new Rect(220,10,100,30),hSlideValue,0,10);        vSlideValue = GUI.VerticalSlider (new Rect(220,40,30,100),vSlideValue,0,5);        //Scrollbar控制項        hSbarValue = GUI.HorizontalScrollbar (new Rect(220,160,100,30),hSbarValue,1,0,10);        vSbarValue = GUI.VerticalScrollbar (new Rect(220,200,30,100),vSbarValue,1,0,10);        //scrollView控制項        scrollPosition = GUI.BeginScrollView (new Rect(430,40,200,200),scrollPosition,new Rect(420,30,550,650));        GUI.Button (new Rect(420,30,100,20),"top-left");        GUI.Button (new Rect(680,30,100,20),"top-right");        GUI.Button (new Rect(420,630,100,20),"bottom-left");        GUI.Button (new Rect(680,630,100,20),"bottom-right");        GUI.EndScrollView ();//結束滾動視圖        //window視窗        windowbox = GUI.Window (0,windowbox,windowFun,"my window");    }    void windowFun ( int windowID){        GUI.Button (new Rect(60,50,100,20),"window Button");        GUI.DragWindow (new Rect(0,0,220,20));    }}

效果

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.