Unity NGUI控件之伪进度条的制作
伪进度条是为了让加载过程更有可视化的一种方法
成品展示如下:
1.创建UI Root,然后在里面建立两个panel控件,一个为progress一个为rate
2.在rate里面添加一个空物体,然后在空物体里添加三个精灵,分别为BackGround,ForeGround和Thumb
3.调节三个精灵的大小,位置和层
4.创建一个脚本ProgressD,将其挂载到空物体里,脚本代码如下
using UnityEngine;
using System.Collections;
public class PregressWFD : MonoBehaviour {
public float duration = 10f;
public UIProgressBar progress;
// Use this for initialization
void Start () {
if (progress == null)
progress = GetComponent<UIProgressBar> ();
GameObject thumb = GameObject.Find ("Thumb");
thumb.AddComponent<MySpriteAnimationWFD> ();
thumb.GetComponent<MySpriteAnimationWFD> ().framesPerSecond = 15;
thumb.GetComponent<MySpriteAnimationWFD> ().loop = true;
// thumb.GetComponent<MySpriteAnimationWFD> ().setSnap (false);
thumb.GetComponent<MySpriteAnimationWFD> ().snap = false;
}
// Update is called once per frame
void Update () {
if (progress.value < 1) {
float value = 1 / duration * Time.deltaTime;
progress.value += value;
} else {
progress.value = 0;
}
}
}
5.在空物体中添加一个Progress Bar的脚本,将三个精灵拖入(对号入座)
6.在progress里创建一个空物体,在空物体里加一个精灵Sprite和一个Label
7.给精灵添加一个TweenRotation的tween动画脚本,并将Label拉倒ProgressBar脚本中On Value Change 中,选择SetCurrentPercent显示百分比
将TweenRotation中的数据修改成这样