using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; public class SceneLoad : MonoSingleton { public GameObject loadingPanel; public Slider loadSlider; public Text loadingInfoText; public bool isLoad = false; public bool isOnece = true; private void Start() { loadingPanel.SetActive(false); } public void SceneChange(string Scenename) { isLoad = true; StartCoroutine(LoadScene(Scenename)); } private void Update() { if (isLoad) { float tt = loadSlider.value += Time.deltaTime * 0.05f; loadingInfoText.text = "加载中 " + (tt * 100f).ToString("0") + "%"; } } private IEnumerator LoadScene(string loadSceneName) { MaskLoadInfoPanel(); UIManager.Instance.time.PauseTimer(); AsyncOperation operation = SceneManager.LoadSceneAsync(loadSceneName); operation.allowSceneActivation = false; while (!operation.isDone) { if (operation.progress >= 0.9f) { isLoad = false; loadSlider.value = 1; loadingInfoText.text = "100%"; operation.allowSceneActivation = true; isOnece = true; } yield return null; } loadingPanel.SetActive(false); if (loadSceneName == "工具间场景" || loadSceneName == "农贸市场" || loadSceneName == "小商户" || loadSceneName == "农家乐" || loadSceneName == "自建房") { UIManager.Instance.time.RunTimer(); if (GlobalFlag.isRecord == "1") { Camera uiCamera = GameObject.FindGameObjectWithTag("UICamera").GetComponent(); if (uiCamera != null) { UIManager.Instance.canvas.worldCamera = uiCamera; } UIManager.Instance.uis.OnStartRecorad(); } } } public void MaskLoadInfoPanel() { if (isOnece) { ResetLoadInfoPanel(true); isOnece = false; } } public void ResetLoadInfoPanel(bool isEnabel) { loadingInfoText.text = "0%"; loadSlider.value = 0; isLoad = isEnabel; loadingPanel.SetActive(isEnabel); } }