IEnumerator LoadAB(string abUrl,string sceneName,Action<int> progressCallBack, Action finishedCallBack)
{
UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(abUrl, 0);
yield return request.SendWebRequest();
AssetBundle ab = DownloadHandlerAssetBundle.GetContent(request);
int currentValue = 0;
int wantValue = 100;
AsyncOperation ao = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
ao.allowSceneActivation = false;
while (ao.progress<0.9f)
{
wantValue = (int)ao.progress * 100;
while (currentValue<wantValue)
{
++currentValue;
progressCallBack?.Invoke(currentValue);
yield return new WaitForSeconds(0.01f);
}
}
wantValue = 100;
while (currentValue<wantValue)
{
++currentValue;
progressCallBack?.Invoke(currentValue);
yield return new WaitForSeconds(0.01f);
}
finishedCallBack?.Invoke();
ao.allowSceneActivation = true;
}
加载AB包中的场景
最新推荐文章于 2024-05-28 11:28:53 发布