Entrance_LevelLoading.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine.SceneManagement;
  5. /// <summary>
  6. ///
  7. /// </summary>
  8. public class Entrance_LevelLoading : MonoBehaviour
  9. {
  10. /// <summary>
  11. /// 异步加载器
  12. /// </summary>
  13. private AsyncOperation async = null;
  14. /// <summary>
  15. /// 当前 Progress
  16. /// </summary>
  17. private float displayProgress = 0;
  18. /// <summary>
  19. /// 是否加载中
  20. /// </summary>
  21. private bool loading = false;
  22. /// <summary>
  23. /// 初始化
  24. /// </summary>
  25. private void Start()
  26. {
  27. AudioManager.Instance.ChangeGameBackMusic(AudioManager.LoadingBackMusic, 0.1f);
  28. loading = true;
  29. displayProgress = 0;
  30. Invoke("Lateload", 0.15f);
  31. }
  32. /// <summary>
  33. /// 延迟加载
  34. /// </summary>
  35. private void Lateload()
  36. {
  37. StartCoroutine(IE_LoadLevel());
  38. }
  39. /// <summary>
  40. /// 协同加载
  41. /// </summary>
  42. /// <returns>返回加载器</returns>
  43. private IEnumerator IE_LoadLevel()
  44. {
  45. if (LevelManager.Instance().mCurLevel == E_Level.Battle)
  46. {
  47. ////if (LevelManager.Instance().mCurLevelResName == "YLBattle_1_ADON")
  48. ////{
  49. //// async = SceneManager.LoadSceneAsync("YLBattle_1_AL");
  50. //// async.allowSceneActivation = false;
  51. ////}
  52. ////else
  53. {
  54. // 开始加载资源
  55. ResourceHelper.Instance.LoadAssetBundle(LevelManager.Instance().mCurLevelResName, (obj) =>
  56. {
  57. // 资源有效
  58. if (obj != null)
  59. {
  60. async = SceneManager.LoadSceneAsync(LevelManager.Instance().mCurLevelResName);
  61. async.allowSceneActivation = false;
  62. }
  63. // 资源无效
  64. else
  65. {
  66. async = SceneManager.LoadSceneAsync(LevelManager.Instance().mCurLevelResName);
  67. async.allowSceneActivation = false;
  68. }
  69. });
  70. }
  71. }
  72. else
  73. {
  74. async = SceneManager.LoadSceneAsync((int)LevelManager.Instance().mCurLevel);
  75. async.allowSceneActivation = false;
  76. }
  77. // 显示加载进度
  78. while (loading)
  79. {
  80. if (async != null)
  81. {
  82. if (async.progress < 0.9f)
  83. {
  84. displayProgress = async.progress + 0.1f;
  85. UI_LoadingWindow.Instance().SetProgress((int)(displayProgress * 100));
  86. }
  87. else
  88. {
  89. loading = false;
  90. displayProgress = 1.0f;
  91. UI_LoadingWindow.Instance().SetProgress(100);
  92. yield return new WaitForSeconds(0.2f);
  93. async.allowSceneActivation = true;
  94. }
  95. }
  96. else
  97. {
  98. displayProgress = ResourceHelper.Instance.GetLoadProgress();
  99. UI_LoadingWindow.Instance().SetProgress((int)(displayProgress * 100));
  100. }
  101. yield return new WaitForSeconds(0.02f);
  102. }
  103. }
  104. }