所谓GUISkin,概括起来就是控件的衣柜,GUISkin(转自海澜之家广告)
为了让控件看起来衣冠楚楚,首先我们需要创建一个GUISkin,在Project视图下点击create,选择GUI Skin,这样一个GUISkin就创建好了,展开Custom Style,设置size的大小为13,下面我们就一步步开始制作游戏界面。
注意:这里只以OPPION选项为例,完整的代码我会在最后上传
一、新建C#脚本
using UnityEngine; using System.Collections;
public class Voice : MonoBehaviour { public GUISkin mySkin;//皮肤管理器 public enum Menu { start = 1, option, help, quit };//枚举各个按钮 public bool fullScreen_bool;//全屏选项 public float BGMslider_float;//背景音乐 public float SoundSlider_float;//音效音乐
public Texture tex;//背景图片 public Texture tex_t;//点击设置选项时挡在背景图片前的黑色底板 public Texture tex_nandu;//点击开始时难度选择的底板 public Texture[] tex_help;//点击帮助时的图片 public int select_T = 0;//标志菜单选择项
public Menu start_t; public Menu option_t; public Menu help_t; public Menu quit_t; public int count;//标志帮助图片当前的张数 public bool helpContinue;//帮助菜单是否点击继续按钮
// Use this for initialization void Start () { start_t = Menu.start; option_t = Menu.option; help_t = Menu.help; quit_t = Menu.quit; } // Update is called once per frame void Update () { } void OnGUI() { GUI.skin = mySkin;
//绘制背景图片 GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), tex);
//绘制整个菜单选项 if (select_T == 0) { //开始 if(GUI.Button(new Rect(402.0f / 1024.0f * Screen.width, 377.0f / 768.0f * Screen.height, 267, 56), "", "start")) { select_T = 1; } //设置 if(GUI.Button(new Rect(402.0f / 1024.0f * Screen.width, 459.0f / 768.0f * Screen.height, 267, 56),"","option")) { select_T = 2; } //帮助 if(GUI.Button(new Rect(402.0f / 1024.0f * Screen.width, 550.0f / 768.0f * Screen.height, 267, 56),"","help")) { select_T = 3; } //退出 if (GUI.Button(new Rect(402.0f / 1024.0f * Screen.width, 638.0f / 768.0f * Screen.height, 267, 56), "", "quit")) { select_T = 4; } }
if (select_T == option_t.GetHashCode()) { GUI.DrawTexture(new Rect((Screen.width - 496) / 2.0f, 20.0f / 768.0f * Screen.height, 496, 651), tex_t); fullScreen_bool = GUI.Toggle(new Rect(510, 450, 39, 38), fullScreen_bool, "", "FullScreen"); BGMslider_float = GUI.HorizontalSlider(new Rect(380, 180, 291, 33), BGMslider_float, 0, 1, "huadongtiao", "huakuai"); SoundSlider_float = GUI.HorizontalSlider(new Rect(380, 330, 291, 33), SoundSlider_float, 0, 1, "huadongtiao", "huakuai"); if (GUI.Button(new Rect((Screen.width - 267) / 2.0f, 660.0f / 768.0f * Screen.height, 267, 56), "", "back")) { select_T = 0; } } } }
二、将脚本拖到猪摄像机,为各项公有参数赋值
三、制作GUISkin
这里需要说明的是
1、name的指必须与GUI的GUIStyle参数一致!
2、Nomal属性即按钮平常的状态,Hover就是鼠标放上去的样子,剩下的参数大家可以根据需要去查文档或者问我
完整项目:http://download.csdn.net/detail/yy8245075/5984695