using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
public class LoadMultiScene : MonoBehaviour
{
[SerializeField]
private CharacterController player = null;
private int loadSceneProgress = 0;
[SerializeField]
private List<string> sceneList = new List<string>();
// Start is called before the first frame update
void Start()
{
player.enabled = false;
StartCoroutine(IELoadSceneName());
}
IEnumerator IELoadSceneName()
{
var basePath = Path.Combine(Application.streamingAssetsPath, "AssetBundle");
var path = Path.Combine(basePath, "AssetBundleNames.json");
var www = UnityWebRequest.Get(path);
yield return www.SendWebRequest();
if (www.result != UnityWebRequest.Result.Success)
{
Debug.Log(www.error);
}
else
{
AssetBundleNames names = JsonUtility.FromJson<AssetBundleNames>(www.downloadHandler.text);
sceneList = names.abNames;
}
yield return IELoadModel();
}
IEnumerator IELoadModel()
{
for (int i = 0; i < sceneList.Count; i++)
{
var basePath = Path.Combine(Application.streamingAssetsPath, Path.Combine("AssetBundle", "WebGL"));
var path = Path.Combine(basePath, sceneList[i]);
var www = UnityWebRequestAssetBundle.GetAssetBundle(path);
yield return www.SendWebRequest();
while (!www.isDone)
{
loadSceneProgress = (int)(www.downloadProgress * 100);
LoadingPanel.Instance.ShowProcess(loadSceneProgress);
yield return null;
}
if (www.result != UnityWebRequest.Result.Success)
{
Debug.Log(www.error);
}
else
{
while (loadSceneProgress < 100)
{
loadSceneProgress += 1;
LoadingPanel.Instance.ShowProcess(loadSceneProgress);
yield return new WaitForFixedUpdate();
}
AssetBundle asset = DownloadHandlerAssetBundle.GetContent(www);
SceneManager.LoadSceneAsync(sceneList[i], LoadSceneMode.Additive);
yield return new WaitForSeconds(0.5f);
player.enabled = true;
LoadingPanel.Instance.SetPanelState(false);
}
}
}
}
11-10
07-21
02-17
4142
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-16