LoadingView.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5. using UnityEngine.UI;
  6. public class LoadingView : PinBallUIBase
  7. {
  8. public Slider slider_Loading;
  9. public Text text_Progress;
  10. protected override void Init()
  11. {
  12. base.Init();
  13. slider_Loading = transform.Find("slider_Loading").GetComponent<Slider>();
  14. text_Progress = transform.Find("text_Progress").GetComponent<Text>();
  15. }
  16. protected override void ShowUIOpt(object[] args)
  17. {
  18. string sceneName = args[0].ToString();
  19. StartCoroutine(AsyncLoadScene(sceneName));
  20. }
  21. /// <summary>
  22. /// 游戏开始后的实时时间(以秒为单位)(只读)。
  23. /// </summary>
  24. float timeOnStartLoadScene;
  25. IEnumerator AsyncLoadScene(string sceneName)
  26. {
  27. timeOnStartLoadScene = Time.realtimeSinceStartup;
  28. //加载场景名
  29. //if (LoginMgr.HasToken())
  30. //{
  31. // sceneName = "Home";
  32. //}
  33. //异步加载场景
  34. AsyncOperation async = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Single);
  35. //阻止当加载完成自动切换
  36. async.allowSceneActivation = false;
  37. while (!async.isDone)
  38. {
  39. slider_Loading.value = async.progress;
  40. text_Progress.text = async.progress * 100 + "%";
  41. if (async.progress >= 0.9f)
  42. {
  43. break;
  44. }
  45. yield return new WaitForSeconds(1);
  46. }
  47. //while (!appVersionCheckOK)
  48. //{
  49. // yield return null;
  50. //}
  51. //while (Time.realtimeSinceStartup - timeOnStartLoadScene < 1.5)
  52. //{
  53. // yield return null;
  54. //}
  55. async.allowSceneActivation = true;
  56. //PinBallUIManager.instance.DestroyUI(new object[] { "LoadingView" });
  57. PinBallUIManager.instance.DestroyAllUI();
  58. //SetTip("软件版本校验成功", Color.green);
  59. // yield return null;
  60. if (sceneName == "Start")
  61. {
  62. PinBallUIManager.instance.ShowUI(new object[] { "StartGameView" });
  63. }
  64. }
  65. protected override void HideUIOpt()
  66. {
  67. }
  68. }