Unity之路(八):GUI/GUILayout示例和Application

GUI 控件使用示例

using UnityEngine;
using System.Collections;

public class test : MonoBehaviour {

    public string ar_str = "";
    public string pwd_str = "";
    public bool tg_val = false;

    void OnGUI (){
        // 文本标签
        GUI.Label(new Rect(10, 30, 100, 50), "label str");

        // 按钮
        if (GUI.Button (new Rect (10, 70, 100, 50), "Buttion")) {
            print ("btn");
        }

        // 长按按钮
        if (GUI.RepeatButton (new Rect (10, 130, 100, 50), "RepeatButton")) {
            print("rpt btn");
        }

        // 输入框
        ar_str = GUI.TextArea(new Rect(10, 190, 100, 30), ar_str);

        // 密码输入框
        pwd_str = GUI.PasswordField(new Rect(10, 230, 100, 30), pwd_str, '*');

        // 选择按钮
        tg_val = GUI.Toggle(new Rect(120, 30, 100, 30), tg_val, "item");
    }
}

GUILayout 控件使用示例

using UnityEngine;
using System.Collections;

public class test : MonoBehaviour {

    public string ar_str = "";
    public string pwd_str = "";
    public bool tg_val = false;

    void OnGUI (){
        GUILayout.BeginVertical();

        // 文本标签
        GUILayout.Label("label str");

        // 按钮
        if (GUILayout.Button ("Buttion")) {
            print ("btn");
        }

        // 长按按钮
        if (GUILayout.RepeatButton ("RepeatButton")) {
            print("rpt btn");
        }

        // 输入框
        ar_str = GUILayout.TextArea(ar_str);

        // 密码输入框
        pwd_str = GUILayout.PasswordField(pwd_str, '*');

        // 选择按钮
        tg_val = GUILayout.Toggle(tg_val, "item");

        GUILayout.EndVertical();
    }
}

可以看到,GUI控件位置大小固定,GUILayout控件位置是相对的,大小根据内容自动适配。

 Application

Application 常用类方法:

public static void LoadLevel(string name/int indxe) 加载场景
public static void CaptureScreen(string filename) 截屏
public static void OpenURL(string url) 打开链接
public static void Quit() 退出

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值