GUI 控件实例学习二(C#)

using UnityEngine;
using System.Collections;

public class GUITest : MonoBehaviour {

    public GUISkin myGUISking;
    private Rect windowRect;
    private Vector2 scrollPosition;
    string info="       测试测试测试测试测试测试测试测试测试测试 \n " +
        "测试测试测试测试测试测试测试测试\n测试测试测试测试测试测试\n测试测试测试测试测试测试测试测试\n测试测试测试测试测试测试测试测试\n" +
            "测试测试测试测试测试测试测试测试测试测试\n测试测试测试测试测试测试测试测试\n测试测试测试测试测试测试";
    // Use this for initialization
    void Start () {
        windowRect = new Rect (500,140,350,510);
    }
    
    // Update is called once per frame
    void Update () {
    
    }
    void OnGUI(){
        GUI.skin = myGUISking;
        windowRect = GUI.Window (0,windowRect,DoMyWindow,"");
    }

    void DoMyWindow( int windowID){
        GUILayout.BeginVertical ();
        GUILayout.Space (8);
        GUILayout.Button ("", "MyButtonSkin");
        GUILayout.Space (8);
        GUILayout.Label ("","MyDividerSkin");
        GUILayout.Label ("MyLabelSkin","MyLabelSkin");
        GUILayout.Label ("","MyDividerSkin");
        GUILayout.Label ("","MyDividerSkin");
        GUILayout.Label ("","MyDividerSkin");
        GUILayout.Label ("","MyDividerSkin");

        GUILayout.BeginHorizontal ();
        scrollPosition = GUILayout.BeginScrollView (scrollPosition, false, true);
        GUILayout.Label (info,"MyTextSkin");
        GUILayout.EndScrollView ();
        GUILayout.EndHorizontal ();

        GUILayout.EndVertical ();
        GUI.DragWindow (new Rect(0,0,10000,10000));
    }

}

GUI 控件实例学习二(C#)_第1张图片

GUI原理很简单,和flash组件差不多,只能unity3d中是可视化编辑,调整各种属性,然后即可得到视图效果。

 

你可能感兴趣的:(GUI)