public class sk : MonoBehaviour {
public static sk instance;
public delegate void DelAfterLoadScene();
DelAfterLoadScene theDel;
private UISlider slider;
//进度条的vlaue
private int barProgress;
AsyncOperation asyn;
private void Awake() {
instance =this;
DontDestroyOnLoad(this.gameObject);
}
public void LoadNextScene(string sceneName,DelAfterLoadScene theDel){
theDel =del;
//开启一个异步任务
slider =GameObject.Find("ProgressBar").GetComponent<UISlider>();
StartCoroutine(LoadScene(sceneName));
/*
LoadSceneHelper.instance.LoadNextScene("LevelScene",delegate {
UIManager.
})
*/
}
IEnumerator LoadScene(string sceneName){
asyn =Application.LoadLevelAsync(sceneName);
asyn.allowSceneActivation =false;
yield return asyn;
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(asyn ==null){
return;
}
int theProgress =0;
//asyn.progress的范围是0-1
if(asyn.progress<0.9f) {
//正在加载场景中ing
theProgress = (int)asyn.progress*100;
}else
{
theProgress=100;
}
if(barProgress <theProgress){
barProgress ++;
}
slider.value =barProgress/100f;
if(barProgress ==100){
asyn.allowSceneActivation = true;
}
if(asyn.isDone){
if(theDel !=null){
theDel();
}
GameTool.ClearMemory();
}
}
}
ui framework - load scene asynchronously
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=325172554&siteId=291194637
Recommended
Ranking