12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- using System;
- using System.Collections;
- using UnityEngine;
- using UnityEngine.UI;
- using QFramework;
- using UnityEngine.SceneManagement;
- namespace QFramework
- {
- public class LoadProgressPanelData : UIPanelData
- {
- }
- public partial class LoadProgressPanel : UIPanel
- {
- private AsyncOperation m_AsyncOperation;
- private float m_CurrentProgress, m_TargetProgress;
-
- protected override void ProcessMsg(int eventId, QMsg msg)
- {
- throw new System.NotImplementedException();
- }
-
- protected override void OnInit(IUIData uiData = null)
- {
- mData = uiData as LoadProgressPanelData ?? new LoadProgressPanelData();
- // please add init code here
- }
- #region 内置函数
- protected override void OnOpen(IUIData uiData = null)
- {
- }
-
- protected override void OnShow()
- {
- }
-
- protected override void OnHide()
- {
- }
-
- protected override void OnClose()
- {
- }
- #endregion
- public void Init(string _sceneName)
- {
- Title.text = "加载中";
- LoadSlider.value = 0;
- m_CurrentProgress = m_TargetProgress = 0;
-
- StartCoroutine(LoadScene(_sceneName));
- }
- private IEnumerator LoadScene(string _sceneName)
- {
- m_AsyncOperation = SceneManager.LoadSceneAsync(_sceneName);
- m_AsyncOperation.allowSceneActivation = false;
- while (m_AsyncOperation.progress < 0.9f)
- {
- m_TargetProgress = (int)m_AsyncOperation.progress * 100;
- yield return LoadProgress();
- }
- m_TargetProgress = 100;
- yield return LoadProgress();
- Title.text = "加载完成";
- m_AsyncOperation.allowSceneActivation = true;
- }
- private IEnumerator LoadProgress()
- {
- while (m_CurrentProgress < m_TargetProgress)
- {
- ++m_CurrentProgress;
- LoadSlider.value = m_CurrentProgress / 100;
- yield return new WaitForEndOfFrame();
- }
- }
- }
- }
|