using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
///
///
///
public class Entrance_LevelLoading : MonoBehaviour
{
///
/// 异步加载器
///
private AsyncOperation async = null;
///
/// 当前 Progress
///
private float displayProgress = 0;
///
/// 是否加载中
///
private bool loading = false;
///
/// 初始化
///
private void Start()
{
AudioManager.Instance.ChangeGameBackMusic(AudioManager.LoadingBackMusic, 0.1f);
loading = true;
displayProgress = 0;
Invoke("Lateload", 0.15f);
}
///
/// 延迟加载
///
private void Lateload()
{
StartCoroutine(IE_LoadLevel());
}
///
/// 协同加载
///
/// 返回加载器
private IEnumerator IE_LoadLevel()
{
if (LevelManager.Instance().mCurLevel == E_Level.Battle)
{
////if (LevelManager.Instance().mCurLevelResName == "YLBattle_1_ADON")
////{
//// async = SceneManager.LoadSceneAsync("YLBattle_1_AL");
//// async.allowSceneActivation = false;
////}
////else
{
// 开始加载资源
ResourceHelper.Instance.LoadAssetBundle(LevelManager.Instance().mCurLevelResName, (obj) =>
{
// 资源有效
if (obj != null)
{
async = SceneManager.LoadSceneAsync(LevelManager.Instance().mCurLevelResName);
async.allowSceneActivation = false;
}
// 资源无效
else
{
async = SceneManager.LoadSceneAsync(LevelManager.Instance().mCurLevelResName);
async.allowSceneActivation = false;
}
});
}
}
else
{
async = SceneManager.LoadSceneAsync((int)LevelManager.Instance().mCurLevel);
async.allowSceneActivation = false;
}
// 显示加载进度
while (loading)
{
if (async != null)
{
if (async.progress < 0.9f)
{
displayProgress = async.progress + 0.1f;
UI_LoadingWindow.Instance().SetProgress((int)(displayProgress * 100));
}
else
{
loading = false;
displayProgress = 1.0f;
UI_LoadingWindow.Instance().SetProgress(100);
yield return new WaitForSeconds(0.2f);
async.allowSceneActivation = true;
}
}
else
{
displayProgress = ResourceHelper.Instance.GetLoadProgress();
UI_LoadingWindow.Instance().SetProgress((int)(displayProgress * 100));
}
yield return new WaitForSeconds(0.02f);
}
}
}