Sprite:图片精灵。可以在一张大图(Atlas,整体图像集合)中去截取一部分,而截取的小图就是一个精灵。给精灵命名后,使用时通过精灵的名称就能直接绘制。图片精灵还可以用来制作动画(Tween相关脚本)。
创建Sprite:


Sprite的属性栏

图片的选择:首先点击Atlas(图册),会弹出图册选择界面,下图中四个图册是NGUI自带的。
我选择的是示范图册是最后一个“Wooden Atals”。

点击精灵,选择图集中的一张图片。

Type:图片样式。有五种样式可供选择。

Simple:标准的Sprite,自适应大小。

Sliced:九宫格切片,创建固定边框控件的最佳选择。边框固定,图片中间做拉伸(缩放),如角色头像,按钮背景。

Tiled:平铺,一个Sprite缩放填充整个区域,如背景平铺。

Filled:每个Sprite有一个单独的参数(file Amout)来控制哪些是可见的,用来制作技能CD冷却时间或进度条。

举个制作技能冷却时间转动的例子:
先添加Cooldown(冷却时间)脚本

下面为Cooldown脚本的代码:
using UnityEngine;
public class Cooldown : MonoBehaviour {
private UISprite mySprite;
void Start () {
mySprite = GetComponent<UISprite>();//实例化
}
void Update () {
}
private void FixedUpdate()
{
if (mySprite.fillAmount != 0)
{
mySprite.fillAmount -= 0.01f;//每0.02s图片减少的1%,即该图片的CD为2秒。
}
else
{
mySprite.fillAmount = 1;//当CD好了的时候(mySprite.fillAmount==0),重置CD
}
}
}
点击运行后,效果图如下,360度的技能冷却就做好了。

Advanced:高级的,自定义左右上下中的Sprite Type。

我们会发现,无论是Label,还是Sprite,都会有Widget和Anchors这两个属性。其实这任何NGUI的控件都有着两个属性,下面我们就来了解Widget和Anchors的用法。

Widget
这个部件属性包含了Sprite的中心点【Pivot】,层级深度【Depth】(当有多个图层的时候就会用到),大小【Size】,还有可调方向【Aspect】。
Pivot:中心点
此时以Sprit的左上角顶点为中心点,所以在对Sprite进行旋转操作时,就围绕左上角顶点进行旋转。

Anchors:对齐方式

Unified

Advanced:四个边的对齐参照物均可自定义选择(也就是说至多可以有四个对其参照物)

感谢观看:)
网友评论