您的位置:首页 > 产品设计 > UI/UE

NGUI使用3——制作图集&自定义按钮&切换按钮图片

2020-02-03 01:53 916 查看

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

  • 点赞
  • 收藏
  • 分享
  • 文章举报
dichuzhi7828 发布了0 篇原创文章 · 获赞 0 · 访问量 178 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: