相对位置参考   http://blog.csdn.net/sunny__chen/article/details/51323265

自适应屏幕收缩  http://www.360doc.com/content/14/0124/09/12282510_347501909.shtml

一、Label

#region 四个角定位

GUI.Label(new Rect(30, 10, 100, 200), "zzzzzz");
        GUI.Label(new Rect(30, Screen.height - 50, 100, 200), "zzzzzz");
        GUI.Label(new Rect(Screen.width - 50, Screen.height - 50, 100, 200), "zzzzzz");
        GUI.Label(new Rect(Screen.width - 50, 10, 100, 200), "zzzzzz");

#endregion

二、Button

GUI.Label(new Rect(30, 30, 100, 200), "Button");
        GUI.Button(new Rect(30, 50, 50, 50), "这个是一个按钮");
        GUI.Button(new Rect(90, 50, 50, 50), text);
        //带图片带文字的按钮
        GUIContent guic = new GUIContent("按钮", text);
        GUI.Button(new Rect(150, 50, 50, 50), guic);
        //按键从上往下排 自动排序
        if (GUILayout.Button("1"))
            Debug.Log("1");
        if (GUILayout.Button("2"))
            Debug.Log("2");
        if (GUILayout.Button("3"))
            Debug.Log("3");
        if (GUILayout.Button("4"))
            Debug.Log("4");
        if (GUILayout.Button("5"))
            Debug.Log("5");
        if (GUILayout.Button("6"))
            Debug.Log("6");
        if (GUILayout.Button("7"))
            Debug.Log("7");
        if (GUILayout.Button("8"))
            Debug.Log("8");

三、Toggle控件

GUI.Label(new Rect(30, 100, 100, 200), "Toggle");
      toggle1 = GUI.Toggle(new Rect(30, 120, 100, 30), toggle1, "Toggle");
      toggle2 = GUI.Toggle(new Rect(30, 150, 100, 30), toggle2, text);

四、滑动条

GUI.Label(new Rect(30, 180, 100, 200), "滑动条");
        hSliderValue = GUI.HorizontalSlider(new Rect(30, 200, 100, 30), hSliderValue, 0, 10);
        Show("水平滑动条:" + hSliderValue);
        vSliderVaule = GUI.VerticalSlider(new Rect(0, 200, 30, 100), vSliderVaule, 0, 10);

五、Toolbar

toolbarInt = GUI.Toolbar(new Rect(30, 250, 250, 30), toolbarInt, new string[] { "功能一", "功能二", "功能
三" });
        if (lastValue != toolbarInt)
        {
            if (toolbarInt == 0)
                Debug.Log(1111);
            if (toolbarInt == 1)
                Debug.Log(2222);
            if (toolbarInt == 2)
                Debug.Log(3333);
            lastValue = toolbarInt;
        }

六、Scrollbar

GUI.Label(new Rect(30, 300, 100, 200), "Scrollbar");
        hSbarValue = GUI.HorizontalScrollbar(new Rect(30, 320, 100, 30), hSbarValue, 1.0f, 0.0f, 10.0f);
        vSbarValue = GUI.VerticalScrollbar(new Rect(0, 320, 30, 100), vSbarValue, 1.0f, 0.0f, 10.0f);

七、菜单

GUI.Box(new Rect(30, 350, 100, 100), "Menu");
        if (GUI.Button(new Rect(40, 370, 80, 20), "1"))

八、TextField

useNmae = GUI.TextField(new Rect(Screen.width / 2, Screen.height / 2 - 200, 150, 30), useNmae);
        //*****密码字符的掩码字符
        passWord = GUI.PasswordField(new Rect(Screen.width / 2, Screen.height / 2 - 150, 150, 30), passWord, '*', 25);
        if (GUI.Button(new Rect(Screen.width / 2, Screen.height / 2 - 50, 150, 30), "登录"))
        {
            isBntLogin = true;
            Debug.Log(isBntLogin+ "isBntLogin");
            if (useNmae.Equals("admin") && passWord.Equals("123"))
            {
                isSuccess = true;
                GUI.Label(new Rect(500, 350, 150, 30), "登录成功");
            }
            else
            {
                isSuccess = false;
                GUI.Label(new Rect(500, 350, 150, 30), "登录失败");
            }

}
        if (isBntLogin)
        {
            if (isSuccess)
                GUI.Label(new Rect(Screen.width / 2, Screen.height / 2 + 50, 150, 30), "登录成功");
            else
            {
                GUI.Label(new Rect(Screen.width / 2, Screen.height / 2 + 50, 150, 30), "登录失败");
            }
        }

=====================================================================================

要考虑屏幕收缩的话,说实话,这个ongui还是太麻烦了

还不如去动态创建ugui呢,自己写个工具就行

参考 http://blog.csdn.net/jwxkk/article/details/52452513

Unity3D之OnGUI知识总结的更多相关文章

  1. Unity3D光照前置知识——Rendering Paths(渲染路径)及LightMode(光照模式)译解

    简述 Unity supports different Rendering Paths. You should choose which one you use depending on your g ...

  2. Unity3D游戏开发——显示物品的仓库UI

    访问仓库物品列表的方法 为了在UI中显示物品列表,我们需要给InventoryManager添加两个能够访问它的公有方法: 代码: ··· public List<string> GetI ...

  3. Unity3D游戏开发初探—4.开发一个“疯狂击箱子”游戏

    一.预备知识—对象的”生“与”死“ (1)如何在游戏脚本程序中创建对象而不是一开始就创建好对象?->使用GameObject的静态方法:CreatePrimitive() 以上一篇的博文中的“指 ...

  4. Unity3D 装备系统学习Inventory Pro 2.1.2 总结

    前言 写在最前面,本文未必适合纯新手,但有一些C#开发经验的还是可以看懂的,虽然本人也是一位Unity3D新人,但是本文只是自己在学习Inventory Pro的学习总结,而不是教程,本人觉得要读懂理 ...

  5. Unity3d UGUI 通用Confirm确认对话框实现(Inventory Pro学习总结)

    背景 曾几何时,在Winform中,使用MessageBox对话框是如此happy,后来还有人封装了可以选择各种图标和带隐藏详情的MessageBox,现在Unity3d UGui就没有了这样的好事情 ...

  6. 在知乎回答的一个问题:C#初学者以后往WP开发走,还是往unity3d走?哪个更有前景呢

    问题原文:我是一个C#初学者,想问个问题,我以后是该往WP开发方向走呢还是学习Unity3D往游戏开发,哪个更有前景呢,个人感觉未来几年iOS,WP,Java会三足鼎立,WP现在有潜力,但是U3D现在 ...

  7. (转)【风宇冲】Unity3D教程宝典之AssetBundles:第一讲

    自:http://blog.sina.com.cn/s/blog_471132920101gz8z.html 原创文章如需转载请注明:转载自风宇冲Unity3D教程学院                 ...

  8. Unity3D开发七惑

    使用Unity3D开发也有大半年了,心中存惑如下,愿与各位开发者一起探讨: (1)  远离普适编程之惑 随着游戏引擎的不断发展,游戏程序员的开发层级也越来越高,以unity3d尤为突出.如果是进行We ...

  9. Unity3D学习笔记1——绘制一个三角形

    目录 1. 绪论 2. 概述 3. 详论 3.1. 准备 3.2. 实现 3.3. 解析 3.3.1. 场景树对象 3.3.2. 绘制方法 4. 结果 1. 绪论 最近想学习一下Unity3d,无奈发 ...

随机推荐

  1. java8之流的基本使用(二)

    概述 流(stream())是java8的一个新特性,主要的作用就是将各种类型的集合转换为流,然后的方便迭代数据用的.例如: //将List类型的集合转换为流 list.stream() 转换为流之后 ...

  2. 2张图简单分析count(0)与count(*)

    以前一直以为count(0)查询效率比count(*)比较高,原因大概是这么认为count(0)只是第一列进行统计,而count(*)所有列放在一起统计(亲,不要误会,这里不是所有列累加哦) 结果真的 ...

  3. C#多线程编程实战1.4终止线程

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  4. Daily translation 3th

    Source url:http://www.nzherald.co.nz/education/news/article.cfm?c_id=35&objectid=11149719 //plac ...

  5. XXX培训机构Python自动化教程目录

  6. "window.location.href"、"location.href"是本页面跳转

    "window.location.href"."location.href"是本页面跳转 "parent.location.href"是上一 ...

  7. 关联关系的接口+unittest实现关联接口

    关联关系的接口: import requests def login(): url = 'http://ip/api/user/login' data = {'username':'niuhang', ...

  8. 1. 时间复杂度(大O表示法)以及使用python实现栈

    1.时间复杂度(大O表示法): O(1) < O(logn) < O(n) < O(nlogn) < O(n2) < O(n3) < O(2n) < O(n! ...

  9. 14、OpenCV Python 直线检测

    __author__ = "WSX" import cv2 as cv import numpy as np #-----------------霍夫变换------------- ...

  10. Python3之json模块

    概念: 序列化(Serialization):将对象的状态信息转换为可以存储或可以通过网络传输的过程,传输的格式可以是JSON,XML等.反序列化就是从存储区域(JSON,XML)读取反序列化对象的状 ...