本文主要是介绍【Unity开发】避免重复加载场景资产AB(AssetBundle)包的优化,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
@[TOC](【Unity开发】避免重复加载场景资产AB(AssetBundle)包的优化)
项目需要远程加载场景AB包,并加载场景。
1、 初始方案
1.1 异步加载场景资产(获取AB包数据)
public IEnumerator LoadAssetFromAB(string url, Action<AssetBundle> assetAB){yield return new WaitForSeconds(0.16f);using (UnityWebRequest webRequest = UnityWebRequestAssetBundle.GetAssetBundle(url)){yield return webRequest.SendWebRequest();if (webRequest.result == UnityWebRequest.Result.Success){var bundle = DownloadHandlerAssetBundle.GetContent(webRequest);assetAB?.Invoke(bundle);}}}
1.2 异步加载场景(进入场景)
// 异步加载远程AB场景public void LoadSceneFromAB(AssetBundle assetAB, string sceneName){// 启动异步线程加载场景StartCoroutine(AssetToScene(assetAB, sceneName));
这篇关于【Unity开发】避免重复加载场景资产AB(AssetBundle)包的优化的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!