NGUI使用3——制作图集&自定义按钮&切换按钮图片
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
}
转载于:https://www.cnblogs.com/lv-sally/p/4555599.html
- 点赞
- 收藏
- 分享
- 文章举报
- NGUI使用3——制作图集&自定义按钮&切换按钮图片
- NGUI使用教程(3) 使用外部图片制作Atlas(图集)
- 【unity】【游戏开发】使用NGUI制作可以左右切换的菜单
- 使用 StoryBoard 实现左右按钮切换图片的浏览效果
- 使用OC通过数组来存放图片并加按钮使之能够切换照片
- 使用BmFont制作NGUI的图片字体
- 使用js制作简易轮播图 (图片切换)
- jquery图片切换插件制作左右按钮与标题文字图片切换
- 灵活使用数组制作图片切换js实现
- 使用 CSS3 制作圆角按钮,无需图片
- ImageView控件的基本使用(点击Button按钮,切换图片显示)
- 基于jquery插件制作左右按钮与标题文字图片切换效果
- NGUI 3.5教程(五)按钮-图片的切换
- NGUI 3.5教程(四)Atlas和Sprite(制作图片按钮)
- 使用BMFont+NGUI利用图片制作自定义字体
- NGUI 3.5教程(四)Atlas和Sprite(制作图片按钮)
- NGUI使用教程(3) 使用外部图片制作Atlas(图集)
- 使用:target实现点击按钮切换图片的功能(纯CSS)
- [Construct 2] 使用9-patch图片制作按钮
- NGUI使用图片制作文字