NGUI使用3——制作图集&自定义按钮&切换按钮图片
2015-06-05 21:18
639 查看
1,准备素材
新建一个文件夹,命名为UITexture。
2,创建Atlas
在Project面板中,进入UITexture 文件夹,选中这两张图片,然后 右键-->【NGUI】-->【Atlas Maker】,之后你会看到 Atlas Maker 的界面:
在 Atlas Maker 界面中,点击【Create】按钮。
之后给这个Atlas 起名为MyAtlas.prefab,点击【保存】。
3,预览Atlas和Sprite
保存之后,这个新的Atlas 就创建好了。可以点击一下【View Sprites】,预览一下创建好的精灵。
制作自定义按钮
(1)在Project面板中,搜索“Control”,也就是搜索控件。之后,会发现NGUI的一堆控件。
(2)找到 Simple Button,拖拽到层级面板下面。我这里把它拖拽到Container下面了。
(3)删除label子对象,在Container组建中(UIscript)Atlas选择图集,在scripte中选择精灵,可以调整精灵大小
(4)OK
切换图片
01
using UnityEngine;
02
using System.Collections;
03
04
public class TestButton : MonoBehaviour {
05
protected bool switchFlag = true;
06
07
// Use this for initialization
08
void Start () {
09
10
}
11
12
void OnClick () {
13
if (this.switchFlag) {
14
this.GetComponent<UISprite> ().spriteName = "pause";
15
this.GetComponent<UIButton> ().normalSprite = "pause";
16
this.switchFlag = false;
17
}
18
else{
19
this.GetComponent<UISprite>().spriteName = "start";
20
this.GetComponent<UIButton>().normalSprite = "start";
21
this.switchFlag = true;
22
}
23
}
24
}
新建一个文件夹,命名为UITexture。
2,创建Atlas
在Project面板中,进入UITexture 文件夹,选中这两张图片,然后 右键-->【NGUI】-->【Atlas Maker】,之后你会看到 Atlas Maker 的界面:
在 Atlas Maker 界面中,点击【Create】按钮。
之后给这个Atlas 起名为MyAtlas.prefab,点击【保存】。
3,预览Atlas和Sprite
保存之后,这个新的Atlas 就创建好了。可以点击一下【View Sprites】,预览一下创建好的精灵。
制作自定义按钮
(1)在Project面板中,搜索“Control”,也就是搜索控件。之后,会发现NGUI的一堆控件。
(2)找到 Simple Button,拖拽到层级面板下面。我这里把它拖拽到Container下面了。
(3)删除label子对象,在Container组建中(UIscript)Atlas选择图集,在scripte中选择精灵,可以调整精灵大小
(4)OK
切换图片
01
using UnityEngine;
02
using System.Collections;
03
04
public class TestButton : MonoBehaviour {
05
protected bool switchFlag = true;
06
07
// Use this for initialization
08
void Start () {
09
10
}
11
12
void OnClick () {
13
if (this.switchFlag) {
14
this.GetComponent<UISprite> ().spriteName = "pause";
15
this.GetComponent<UIButton> ().normalSprite = "pause";
16
this.switchFlag = false;
17
}
18
else{
19
this.GetComponent<UISprite>().spriteName = "start";
20
this.GetComponent<UIButton>().normalSprite = "start";
21
this.switchFlag = true;
22
}
23
}
24
}
相关文章推荐
- NGUI使用2——Button -- 按钮
- NGUI使用1——label
- UI进阶 —— 收起键盘方法
- UIGestureRecognizer 六种手势的用法 - iOS - UI基础知识总结6
- 一次性移除一个 UIView 所有子视图的方法
- HDU Children’s Queue
- HDU 3836 Equivalent SetsTarjan+缩点)
- 精美UI欣赏
- java 优先队列 PriorityQueue<E>
- UITableView_6-团购实例,刷新数据,代理实现,GCD方法使用
- Android中的volley_11_Request
- DuiLib : CControlUI->SetAttribute(L"pos"后, 属性不生效的问题
- iOS UILabel显示html标签
- WorldWind源码剖析系列:下载请求类DownloadRequest
- WorldWind源码剖析系列:下载队列类DownloadQueue
- GCD刷新UI
- ios-系统字体一览UIFont
- BZOJ 4059 Cerc2012 Non-boring sequences 线段树+扫描线
- NGUI: UIPanel控件
- VMware GSX Server 3.2.1 Build 19281免费下载