42 lines
1.2 KiB
C#
42 lines
1.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
public class Loading : MonoBehaviour
|
|
{
|
|
public Scrollbar LoadScroll;//加载进度条
|
|
public Text Text_Step;
|
|
public string SceneName_Learn, SceneName_Operation;
|
|
void Start()
|
|
{
|
|
Invoke("StartLoadLevel", 1);//延时2秒开始加载
|
|
}
|
|
void StartLoadLevel()
|
|
{
|
|
StartCoroutine(LoadLevel());
|
|
}
|
|
int Mode;
|
|
AsyncOperation Operation;
|
|
IEnumerator LoadLevel()
|
|
{
|
|
//Mode = PlayerPrefs.GetInt("Mode", 0);
|
|
//if (Mode == 0)
|
|
// Operation = SceneManager.LoadSceneAsync(SceneName_Learn);//加载的场景
|
|
//else
|
|
Operation = SceneManager.LoadSceneAsync(SceneName_Operation);//加载的场景
|
|
Operation.allowSceneActivation = false;
|
|
while (!Operation.isDone)//正在加载
|
|
{
|
|
LoadScroll.size = Operation.progress;
|
|
Text_Step.text = (Operation.progress * 100).ToString("0") + "%";
|
|
if (LoadScroll.size >= 0.9f)
|
|
{
|
|
Operation.allowSceneActivation = true;//允许跳转
|
|
}
|
|
yield return null;
|
|
}
|
|
}
|
|
}
|