Unity3D笔记 GUI 二 、实现选项卡一窗口
实现目标:
1、个性化Box控件
2、新建TextAmount样式
3、新建TextItem样式
一、个性化Windows界面
设置GUI Skin

1.2 部分代码
Rect stateBox = new Rect(, , , );
Rect weaponBox = new Rect(, , , ); GUI.Box(stateBox, "");
GUI.Box(weaponBox, "");//['wepən] n. 武器,兵器
1.3效果

二、新建TextAmount样式
2.1、 代码
#region 个性化Box控件
Rect stateBox = new Rect(, , , );
Rect weaponBox = new Rect(, , , );
public Texture box1;
public Texture box2;
public Texture box3;
Rect box1Rect = new Rect(, , , );
Rect box2Rect = new Rect(, , , );
Rect box3Rect = new Rect(, , , );
#endregion #region 实现Status窗口
GUI.Box(stateBox, "");
GUI.Box(weaponBox, "");//['wepən] n. 武器,兵器
GUI.DrawTexture(box1Rect, box1);
GUI.DrawTexture(box2Rect, box2);
GUI.DrawTexture(box3Rect, box3);
#endregion
2.2、


2.3、效果

2.4、TextAmount

三、新建TextItem样式
3.1、个性化数字的现实

3.2、代码:
using UnityEngine;
using System.Collections; public class myTest : MonoBehaviour
{
/// <summary>
/// 是否打开窗口
/// </summary>
bool isOpenMenu = false;
/// <summary>
/// 窗体的大小和位置【矩形】
/// </summary>
Rect myWindow = new Rect(, , , );
/// <summary>
/// GUI Skin
/// </summary>
public GUISkin customSkin;
/// <summary>
/// 关闭按钮
/// </summary>
Rect closeButton = new Rect(, , , ); /// <summary>
/// 用于工具栏在屏幕上的矩形位置
/// </summary>
Rect tabButton = new Rect(, , , );
/// <summary>
/// 选项卡索引号
/// </summary>
int toolsCount = ;
/// <summary>
/// 显示在工具栏按钮上的字符串数组
/// </summary>
string[] toolsName = { "选项卡1", "选项卡2", "选项卡3" }; /// <summary>
/// 选项卡中的图片
/// </summary>
public Texture img;
/// <summary>
/// 选项卡中的图片位置
/// </summary>
Rect imgRect = new Rect(, , , ); #region 个性化Box控件
Rect stateBox = new Rect(, , , );
Rect weaponBox = new Rect(, , , );
public Texture box1;
public Texture box2;
public Texture box3;
Rect box1Rect = new Rect(, , , );
Rect box2Rect = new Rect(, , , );
Rect box3Rect = new Rect(, , , );
#endregion #region 实现Status窗口
GUIContent guiWeaponCon = new GUIContent();
GUIContent guiArmorCon = new GUIContent();
GUIContent guiAccessCon = new GUIContent();
GUIContent guiSkillCon = new GUIContent();
Rect weaponLable = new Rect(, , , );
Rect armorLable = new Rect(, , , );
Rect accessLable = new Rect(, , , );
Rect skillLable = new Rect(, , , );
string uneuip = "Hello";
Rect hpLabel = new Rect(, , , );
Rect mpLabel = new Rect(, , , );
Rect lvLabel = new Rect(, , , );
Rect expLabel = new Rect(, , , );
Rect nextLabel = new Rect(, , , );
Rect atkLabel = new Rect(, , , );
Rect defLabel = new Rect(, , , );
Rect agiLabel = new Rect(, , , );
Rect intLabel = new Rect(, , , );
Rect lucLable = new Rect(, , , );
int fullHP = ;
int fullMP = ;
int hp = ;
int mp = ;
int lv = ;
int exp = ;
int next = ;
int atk = ;
int def = ;
int agi = ;
int ints = ;
int luc = ;
#endregion // Use this for initialization
void Start()
{
isOpenMenu = false;
guiWeaponCon = new GUIContent(uneuip);
guiArmorCon = new GUIContent(uneuip);
//guiAccessCon = new GUIContent(uneuip); //位置 要调节下 目前位置有点错位
guiSkillCon = new GUIContent(uneuip);
} // Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.M))//当通过名称指定的按键被用户按住时返回true
{
isOpenMenu = true;
}
} void OnGUI()
{
GUI.skin = customSkin;
if (isOpenMenu)
{
int windowId = ;
myWindow = GUI.Window(windowId, myWindow, WindowFunction, "Hello Window");
#region Mathf.Clamp 限制
// 限制value的值在min和max之间, 如果value小于min,返回min。 如果value大于max,返回max,否则返回value
myWindow.x = Mathf.Clamp(myWindow.x, , Screen.width - myWindow.width);// [klæmp] vt.& vi. 夹紧,夹住;锁住;把(砖等)堆高
myWindow.y = Mathf.Clamp(myWindow.y, , Screen.height - myWindow.height);
#endregion
}
} void WindowFunction(int windowId)
{ //begin 关闭按钮
if (GUI.Button(closeButton, "", GUI.skin.GetStyle("closeButton")))
{
isOpenMenu = false;//单击关闭按钮:窗口菜单关闭
}
//end //beign 选项卡
//返回int类型,被选择按钮的索引号
toolsCount = GUI.Toolbar(tabButton, toolsCount, toolsName, GUI.skin.GetStyle("tabButton"));//工具栏
//end //begin 选项卡图片
GUI.DrawTexture(imgRect, img); //end
GUI.DragWindow();//拖动窗口 #region 实现Status窗口
switch (toolsCount)
{
case :
StatusWindow();
break;
case :
break;
case :
break;
default:
break;
}
#endregion } void StatusWindow()
{ GUI.Box(stateBox, "");
GUI.Box(weaponBox, "");//['wepən] n. 武器,兵器
GUI.DrawTexture(box1Rect, box1);
GUI.DrawTexture(box2Rect, box2);
GUI.DrawTexture(box3Rect, box3); GUI.Label(hpLabel, hp.ToString() + "/" + fullHP.ToString(), "TextAmount");
GUI.Label(mpLabel, mp.ToString() + "/" + fullMP.ToString(), "TextAmount");
GUI.Label(lvLabel, lv.ToString(), "TextAmount");
GUI.Label(expLabel, exp.ToString(), "TextAmount");
GUI.Label(nextLabel, next.ToString(), "TextAmount");
GUI.Label(atkLabel, atk.ToString(), "TextAmount");
GUI.Label(defLabel, def.ToString(), "TextAmount");
GUI.Label(agiLabel, agi.ToString(), "TextAmount");
GUI.Label(intLabel, ints.ToString(), "TextAmount"); GUI.Label(lucLable, luc.ToString());
GUI.Label(weaponLable, guiWeaponCon, "TextItem");
GUI.Label(armorLable, guiArmorCon, "TextItem");
GUI.Label(accessLable, guiAccessCon, "TextItem");
GUI.Label(skillLable, guiSkillCon, "TextItem"); } }
3.3、最终效果

Unity3D笔记 GUI 二 、实现选项卡一窗口的更多相关文章
- Unity3D笔记 GUI 四、实现选项卡三
一.代码: using UnityEngine; using System.Collections; /// <summary> /// 选项卡二 /// </summary> ...
- Unity3D笔记 GUI 三、实现选项卡二窗口
实现目标: 1.使用个性化Box控件 2.个性化Lable控件 3.添加纵向滚动条 4.新建SelectedItem样式 一.最终效果: 二.主要代码 using UnityEngine; using ...
- Unity3D笔记 GUI 一
要实现的功能: 1.个性化Windows界面 2.减少个性化的背景图片尺寸 3.个性化样式ExitButton和TabButton 4.实现三个选项卡窗口 一.个性化Windows界面 1.1.创建一 ...
- Unity3D笔记 愤怒的小鸟<二> 实现Play界面
创建Play界面.能个把各个图片组合成一个场景,场景组成后背景能够不停的滚动,当鼠标单击时显示图片手型鼠标 一.GUI Texture 1.创建背景.地面.树木.草 ,这里注意Z轴的排序,一层一层则第 ...
- JavaScript学习笔记(二)——选项卡小结
Js制作选项卡小结 1.先构思好需要展示的页面效果,比如这样 2.需要显示的效果通过html和css制作出来,包括选项(第一课.第二课)的鼠标停留背景变色.下方选项页内容切换的内容等. 3.把此选项卡 ...
- Qt+ECharts开发笔记(二):Qt窗口动态调整大小,使ECharts跟随Qt窗口大小变换而变换大小
前言 上一篇将ECharts嵌入Qt中,在开始ECharts使用之前,还有一个很重要的功能,就是在窗口变换大小的时候,ECharts的图表尺寸也要跟随Qt窗口变换大小而变换大小. Demo演示 ...
- Unity3D笔记十二 游戏元素二之摄像机
一.摄像机 摄像头用以捕捉和显示的世界给玩家.通过自定义和操纵相机,你可以让你的游戏的呈现真正独一无二的.您可以在一个场景无限数量的摄像机.它们可以设置在任何顺序呈现在屏幕上的任何地方,或者屏幕的某些 ...
- Unity3D笔记六 GUI游戏界面
1.Label:标签控件,可以在游戏中用来展示文本字符串信息,不仅可以写字还可以贴图片. 2.Button:按钮控件,一般分图片按钮和普通的按钮,还有一个连续按钮RepeatButton注意,这个在W ...
- 关于ARP欺骗与MITM(中间人攻击)的一些笔记( 二 )
一直没有折腾啥东西,直到最近kali Linux发布,才回想起应该更新博客了….. 再次说明,这些技术并不是本人原创的,而是以前记录在Evernote的旧内容(排版不是很好,请谅解),本文是继关于AR ...
随机推荐
- Oracle:oracle 12.1.0.2 升级到12.2.0.1 后,自动任务报错:ORA-20001: Statistics Advisor: Invalid task name for the current user
具体错误如下:关键字:ORA-12012.ORA-20001 ORA-12012: error on auto execute of job "SYS"."ORA$AT_ ...
- 带有logo的二维码
摘要: 前面介绍了使用javascript生成二维码,但是这样并不能满足我们的需求,我们有时也会看到带有logo的二维码,本文就介绍如何生成带有logo的二维码. 简介: 主要使用了svg的文本和图像 ...
- 使用Socket抓取网页源码
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import ...
- SpringBoot------Eclipce配置Spring Boot
步骤一: 步骤二: 点击左下角Eclipse图标下的“Popular”菜单,选择Spring安装(已安装的插件在Installed中显示),一直按步骤确定就好了,如果中途下载超时什么的,就看看自己的网 ...
- linux环境下执行RF测试脚本
1. 测试执行 测试管理平台需根据用户选中的测试案例,按照相应格式对执行启动命令进行组装和发送,触动案例的自动化测试执行. 命令格式根据测试模式(以项目为单位.以测试集为单位.以案例为单位)具有不同的 ...
- MHL相关资源链接
http://www.mhlconsortium.org/ 消费者网站: www.meetmhl.com采用者网站:www.mhltech.org 博客http://blog.sina.com.cn/ ...
- 执行Batch批处理遇到的问题
1.务必关掉自动提交 增强执行效率 conn.setAutoCommit(false); 2.executeBatch失效问题 <1>务必将语句pstmt = conn.prepareSt ...
- Kindeditor问题
1.初始的时候,拿到切图,kindeditor不知道为什么就是显示不出来,只出来个文本框一样的东西 原因:样式未加载,这个是因为美工那边样式重调了,而且新项目并没有将整个插件拷贝过来,而只是拿了kin ...
- 【大数据系列】节点的退役和服役[datanode,yarn]
一.datanode添加新节点 1 在dfs.include文件中包含新节点名称,该文件在名称节点的本地目录下 [白名单] [s201:/soft/hadoop/etc/hadoop/dfs.incl ...
- 解决:SqlDateTime 溢出。必须介于 1/1/1753 12:00:00 AM 和 12/31/9999 11:59:59 PM 之间提示问题
提示信息如下 “/”应用程序中的服务器错误. SqlDateTime 溢出.必须介于 1/1/1753 12:00:00 AM 和 12/31/9999 11:59:59 PM 之间. 问题现象: 问 ...