83 lines
2.4 KiB
C#
83 lines
2.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
|
|
public class SceneLoad : MonoSingleton<SceneLoad>
|
|
{
|
|
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<Camera>();
|
|
// if (uiCamera != null)
|
|
// {
|
|
// UIManager.Instance.canvas.worldCamera = uiCamera;
|
|
// }
|
|
//}
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|