public GameObject BtnGaoLu;
public UISlider MyUISlider;
private bool isLoad=false;
private AsyncOperation async;
float progress = 0;
void Awake()
{
UIEventListener.Get(BtnGaoLu).onClick = fnChangeSence;
MyUISlider.alpha = 0;
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//繪制進度條,但是由於時間太短,效果不好
if (isLoad)
{
MyUISlider.alpha = 1;
progress = Convert.ToSingle((async.progress.ToString("f2")));
if (progress > 0)
{
MyUISlider.GetComponent<UISlider>().value = progress+0.8f;
//此處添加0.8f是因為我只加載到85%就跳轉了,為了達到進度條到達100*的效果,所以添加了0.8,是實際情況而定。
print(progress);
}
}
}
void fnChangeSence(GameObject obj)
{
StartCoroutine(fnLoadSence("Final_Scene"));
}
IEnumerator fnLoadSence(string strSenceName)
{
isLoad = true;
async = Application.LoadLevelAsync(strSenceName);
yield return async;
}