123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine.SceneManagement;
- /// <summary>
- ///
- /// </summary>
- public class Entrance_LevelLoading : MonoBehaviour
- {
- /// <summary>
- /// 异步加载器
- /// </summary>
- private AsyncOperation async = null;
- /// <summary>
- /// 当前 Progress
- /// </summary>
- private float displayProgress = 0;
- /// <summary>
- /// 是否加载中
- /// </summary>
- private bool loading = false;
- /// <summary>
- /// 初始化
- /// </summary>
- private void Start()
- {
- AudioManager.Instance.ChangeGameBackMusic(AudioManager.LoadingBackMusic, 0.1f);
- loading = true;
- displayProgress = 0;
- Invoke("Lateload", 0.15f);
- }
- /// <summary>
- /// 延迟加载
- /// </summary>
- private void Lateload()
- {
- StartCoroutine(IE_LoadLevel());
- }
- /// <summary>
- /// 协同加载
- /// </summary>
- /// <returns>返回加载器</returns>
- 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);
- }
- }
- }
|