Unity3D游戏开发之跟踪已下载资源包浅析.docx
上传人:qw****27 上传时间:2024-09-11 格式:DOCX 页数:3 大小:16KB 金币:15 举报 版权申诉
预览加载中,请您耐心等待几秒...

Unity3D游戏开发之跟踪已下载资源包浅析.docx

Unity3D游戏开发之跟踪已下载资源包浅析.docx

预览

在线预览结束,喜欢就下载吧,查找使用更方便

15 金币

下载此文档

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

Unity3D游戏开发之跟踪已下载资源包浅析KeepingtrackofloadedAssetBundles跟踪已下载资源包Unity一次只允许加载一个特定资源包(AssetBundle)实例到应用程序中。这意味着您无法检索WWW对象中之前已加载的相同资源包(AssetBundle)或尚未加载的资源包。实际上,这意味着您尝试访问之前已下载的如下资源包(AssetBundle)时:AssetBundlebundle=www.assetBundle;程序将引出以下错误CannotloadcachedAssetBundle.AfileofthesamenameisalreadyloadedfromanotherAssetBundle且资源包属性将返回null。如果第一次下载时下载了该资源包(AssetBundle),则第二次下载时无法检索到该资源包,因此,无需再使用该资源包时,可以将其卸载或获取其引用,并在它存在于内存中时避免将其下载。可根据需求决定需要采取的相应措施,但我们建议在加载完对象后立即卸载该资源包(AssetBundle)。这可释放内存空间,并且不会再收到有关加载已缓存资源包(AssetBundles)的错误。文章出处HYPERLINK"http://www.gopedu.com/"【狗刨学习网】如需跟踪已下载资源包(AssetBundles),可使用包装类协助管理下载,如下:usingUnityEngine;usingSystem;usingSystem.Collections;usingSystem.Collections.Generic;staticpublicclassAssetBundleManager{//AdictionarytoholdtheAssetBundlereferencesstaticprivateDictionary<string,AssetBundleRef>dictAssetBundleRefs;staticAssetBundleManager(){dictAssetBundleRefs=newDictionary<string,AssetBundleRef>();}//ClasswiththeAssetBundlereference,urlandversionprivateclassAssetBundleRef{publicAssetBundleassetBundle=null;publicintversion;publicstringurl;publicAssetBundleRef(stringstrUrlIn,intintVersionIn){url=strUrlIn;version=intVersionIn;}};//GetanAssetBundlepublicstaticAssetBundlegetAssetBundle(stringurl,intversion){stringkeyName=url+version.ToString();AssetBundleRefabRef;if(dictAssetBundleRefs.TryGetValue(keyName,outabRef))returnabRef.assetBundle;elsereturnnull;}//DownloadanAssetBundlepublicstaticIEnumeratordownloadAssetBundle(stringurl,intversion){stringkeyName=url+version.ToString();if(dictAssetBundleRefs.ContainsKey(keyName))yieldreturnnull;else{using(WWWwww=WWW.LoadFromCacheOrDownload(url,version)){yieldreturnwww;if(www.error!=null)thrownewException("WWWdownload:"+www.error);AssetBundleRefabRef=newAssetBundleRef(url,version);abRef.assetBundle=www.assetBundle;dictAssetBundleRefs.Add(keyName,abRef);}}}//UnloadanAssetBundlepublicstaticvoidUnload(stringurl,intversion,boolallObjects){stringkeyName=url+version.ToS