(Atlas maker)图集制作 及 UI Sprite显示图片
图集
图集是图片的一种压缩格式
在NGUI中使用图集为单位进行图片的保存与管理
Atlas maker
NGUI自带的图集制作工具
使用方法
- NGUI菜单 ->open -> Atlas maker
- 在打开的界面中选择右上角的new按钮新建图集
- 将想要打包成图集的图片拖进Project面板,点选图片资源后进行打包
图集的管理
随着项目的进行可能需要对图集中的资源进行修改,这时少不了对图集的修改和更新操作
Tip: 打包的图片不能存在重名
UI Sprite
在NGUI中负责图片的显示
属性面板
- Atlas 指定图集
- Sprite 指定图集中的某张图片
- Type 图片的显示方式 (1)simple (2)Sliced 分割模式 用于解决图片放大失真的问题 (3)Tiled 平铺模式 图片随着size区域的大小而变化,如果区域过大则会显示多张,过小则显示不完整 (4)Filled 填充模式 可以用来制作技能cd效果,或者是切换动画
- depth 深度 深度越高图片的渲染优先级越高 ,即深度高的图片会覆盖深度低的图片
代码控制Sprite创建
该脚本绑定在 UI Root上
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| using UnityEngine; public class CodeContCreat : MonoBehaviour { void Start () { //获取UIRoot的transform组件 Transform t = gameObject.GetComponent<Transform>(); //创建一个名为CodeControl的空对象 GameObject UISprite = new GameObject("CodeControl"); //设置空物体的父对象为UIRoot UISprite.GetComponent<Transform>().SetParent(t); //重置空物体Scale属性 重置一定要放在设置父对象之后,否则重置效果会被覆盖 UISprite.GetComponent<Transform>().localScale = Vector3.one; //加载图集 UIAtlas atlas = Resources.Load<UIAtlas>("UI Atlas"); //为空对象赋予UI Sprite组件并获取 UISprite Sprite=UISprite.AddComponent<UISprite>(); //指定图集 Sprite.atlas = atlas; //指定图片 Sprite.spriteName = "bg"; } }
|
代码添加图片的效果