using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public enum Scenetype
{
Login,//开始场景
Main//战斗场景
}
public class UILoadingView : MonoBehaviour
{
public static Scenetype scentype;
public Slider slider;
public Text text;
private AsyncOperation async;
void Start ()
{
if (scentype == Scenetype.Main)
{
async = SceneManager.LoadSceneAsync("Main");
}
else if (scentype == Scenetype.Login)
{
async = SceneManager.LoadSceneAsync("Login");
}
//异步跳转
// async = SceneManager.LoadSceneAsync(JianJie.Instance.Path_ );
async.allowSceneActivation = false;
}
private int progpress;
private int currprogpress;
void Update ()
{
OnTime();
}
public void OnTime()
{
if (async != null)
{
if (async.progress < 0.9)//跳转加载进度
{
//使加载不生硬
progpress = Mathf.Clamp((int)async.progress * 100, 1, 100);
}
else
{
progpress = 100;
}
if (currprogpress < progpress)
{
currprogpress++;
slider.value = currprogpress / 100.0f;
text.text = string.Format("{0}%", currprogpress );
}
else
{
slider.value = 1;
currprogpress = 100;
text.text = string.Format("{0}%", currprogpress);
async.allowSceneActivation = true;
}
}
}
}