Unity3D笔记 GUI 二 、实现选项卡一窗口
2014-02-22 22:52
531 查看
实现目标:
1、个性化Box控件
2、新建TextAmount样式
3、新建TextItem样式
1.2 部分代码
1.3效果
2.2、
2.3、效果
2.4、TextAmount
3.2、代码:
3.3、最终效果
1、个性化Box控件
2、新建TextAmount样式
3、新建TextItem样式
一、个性化Windows界面
设置GUI Skin1.2 部分代码
Rect stateBox = new Rect(237, 67, 360, 147); Rect weaponBox = new Rect(237, 230, 360, 147); GUI.Box(stateBox, ""); GUI.Box(weaponBox, "");//['wepən] n. 武器,兵器
1.3效果
二、新建TextAmount样式
2.1、 代码#region 个性化Box控件 Rect stateBox = new Rect(237, 67, 360, 147); Rect weaponBox = new Rect(237, 230, 360, 147); public Texture box1; public Texture box2; public Texture box3; Rect box1Rect = new Rect(252, 77, 331, 125); Rect box2Rect = new Rect(252, 244, 331, 125); Rect box3Rect = new Rect(460, 284, 117, 125); #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(10, 10, 640, 480); /// <summary> /// GUI Skin /// </summary> public GUISkin customSkin; /// <summary> /// 关闭按钮 /// </summary> Rect closeButton = new Rect(598, 8, 26, 22); /// <summary> /// 用于工具栏在屏幕上的矩形位置 /// </summary> Rect tabButton = new Rect(35, 15, 490, 40); /// <summary> /// 选项卡索引号 /// </summary> int toolsCount = 0; /// <summary> /// 显示在工具栏按钮上的字符串数组 /// </summary> string[] toolsName = { "选项卡1", "选项卡2", "选项卡3" }; /// <summary> /// 选项卡中的图片 /// </summary> public Texture img; /// <summary> /// 选项卡中的图片位置 /// </summary> Rect imgRect = new Rect(19, 35, 225, 441); #region 个性化Box控件 Rect stateBox = new Rect(237, 67, 360, 147); Rect weaponBox = new Rect(237, 230, 360, 147); public Texture box1; public Texture box2; public Texture box3; Rect box1Rect = new Rect(252, 77, 331, 125); Rect box2Rect = new Rect(252, 244, 331, 125); Rect box3Rect = new Rect(460, 284, 117, 125); #endregion #region 实现Status窗口 GUIContent guiWeaponCon = new GUIContent(); GUIContent guiArmorCon = new GUIContent(); GUIContent guiAccessCon = new GUIContent(); GUIContent guiSkillCon = new GUIContent(); Rect weaponLable = new Rect(252, 240, 180, 40); Rect armorLable = new Rect(252, 340, 180, 40); Rect accessLable = new Rect(252, 360, 180, 40); Rect skillLable = new Rect(252, 288, 180, 40); string uneuip = "Hello"; Rect hpLabel = new Rect(313, 70, 120, 25); Rect mpLabel = new Rect(313, 102, 120, 25); Rect lvLabel = new Rect(313, 120, 120, 25); Rect expLabel = new Rect(313, 150, 120, 25); Rect nextLabel = new Rect(313, 176, 120, 25); Rect atkLabel = new Rect(529, 71, 50, 25); Rect defLabel = new Rect(529, 100, 50, 25); Rect agiLabel = new Rect(529, 120, 50, 25); Rect intLabel = new Rect(529, 150, 50, 25); Rect lucLable = new Rect(529, 180, 50, 25); int fullHP = 9999; int fullMP = 99999; int hp = 9999; int mp = 999; int lv = 90; int exp = 1000; int next = 909; int atk = 123; int def = 345; int agi = 444; int ints = 666; int luc = 8888; #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 = 0; 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, 0, Screen.width - myWindow.width);// [klæmp] vt.& vi. 夹紧,夹住;锁住;把(砖等)堆高 myWindow.y = Mathf.Clamp(myWindow.y, 0, 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 0: StatusWindow(); break; case 1: break; case 2: 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 四、实现选项卡三
- Java GUI:不用JDialog实现窗口跳转后无法操作原窗口
- Unity3D笔记(二)使用GUI做井字棋小游戏
- 【Unity3D游戏开发学习笔记】(八)Unity观察视角的实现
- Unity3d笔记:如何实现不规则多边形按钮
- Unity3D自学笔记——实现2D物体漂浮在制定3D物体上方
- Unity3D ARPG游戏开发《最初的幻想》之GUI背包系统实现
- Unity3D单击物体弹出GUI窗口
- 【Unity3D游戏开发学习笔记】(七)上帝之眼—第三人称摄像机的简单实现(跟随视角,自由视角)
- 【Unity3D API的学习与使用】Unity实现GUI组件的位移、缩放和旋转
- Unity3D笔记 愤怒的小鸟<三> 实现Play界面2
- 【安卓笔记】使用ViewPager+Fragment实现选项卡切换效果
- CSS学习笔记-附加篇( CSS+JS实现的选项卡效果(html组件))
- [Unity3D]手机3D游戏开发:如何实现最高分的存储与显示(二)----使用GUI.Box显示文字
- 基于 WPF 的酷炫 GUI 窗口的简易实现
- Unity3D笔记七 GUILayout
- QT笔记之实现阴影窗口
- 调用DOS实现窗口隐藏并且把DOS控制台下输出信息写入文件中保存 笔记.
- Unity3D自学笔记——UGUI背包系统(五)沿用Attribute设计实现物品等级