Unity-其他控件

作者: 上善若水jf | 来源:发表于2016-10-28 23:45 被阅读75次

    void OnGUI ( )1、Toggle开关按钮

    public Rect rea;

    void Start ( ){

    rea = new Rect(100,50,200,100);

    }

    void OnGUI ( )

    {

       toggle = GUI.Toggle(rea,toggle,"ThisisToggle");

    }

    2、Toolbar工具条

    bool toggle = false;

    void OnGUI ( )

    {

    toolbar = GUI.Toolbar(rea,toolbar,newstring[]{"toolbar_A","toolbar_B","toolbar_C"});

    }

    3、SelectionGrid网格按钮

    void OnGUI ( )

    {

    toolbar = GUI.SelectionGrid(rea,toolbar,newstring[ ]

    {"toolbar_A","toolbar_B","toolbar_C","toolbar_D","toolbar_E"},3);  

    }

    4、HorizontalSlider水平滑块条和HorizontalSlider竖直滑块条

    float sliderF = 3.0f;

    void OnGUI ( )

    {

    //HorizontalSlider水平滑块条

    sliderF=GUI.HorizontalSlider(rea,sliderF,0.0f,10f);

    //HorizontalSlider竖直滑块条

    sliderF=GUI.VerticalSlider(rea,sliderF,0.0f,10f);

    }

    5、HorizontalScrollbar水平滚动条和VerticalScrollbar竖直滚动条

    void OnGUI ( )

    {

    //HorizontalScrollbar水平滚动条

    sliderF=GUI.HorizontalScrollbar(rea,sliderF,1f,0.0f,10f);

    //VerticalScrollbar竖直滚动条

    sliderF=GUI.VerticalScrollbar(rea,sliderF,1f,0.0f,10f);

    }

    6、BeginScrollView滚动视图

    Vector2 scrollPosition = Vector2.zero;

    public Rect scrollArea =new Rect(0,0,200,200);

    void OnGUI ( ){

    scrollPosition=GUI.BeginScrollView(rea,scrollPosition,scrollArea);

    GUI.Button(newRect(0,0,100,20),"Top-left");

    GUI.Button(newRect(120,0,100,20),"Top-right");

    GUI.Button(newRect(0,180,100,20),"botton-left");

    GUI.Button(newRect(120,180,100,20),"botton-right");

    GUI.EndScrollView();

    }

    7、Window添加窗口;ModalWindow表示永远在最上面

    void OnGUI ( )

    {

    rea=GUI.Window(0,rea,windowFunction,"Mywindow");

    }

    void windowFunction (int windowId) {

    GUI.Button(new Rect(60,50,100,20),"window");

    GUI.DragWindow();

    }

    相关文章

      网友评论

        本文标题:Unity-其他控件

        本文链接:https://www.haomeiwen.com/subject/qngeuttx.html