Keeping track of loaded AssetBundles 跟踪已下载资源包
Unity 一次只允许加载一个特定资源包 (AssetBundle) 实例到应用程序中。这意味着您无法检索 WWW 对象中之前已加载的相同资源包 (AssetBundle) 或尚未加载的资源包。实际上,这意味着您尝试访问之前已下载的如下资源包 (AssetBundle) 时:
AssetBundle bundle = www.assetBundle;
程序将引出以下错误
Cannot load cached AssetBundle.A file of the same name is already loaded from another AssetBundle
且资源包属性将返回 null。如果第一次下载时下载了该资源包 (AssetBundle),则第二次下载时无法检索到该资源包,因此,无需再使用该资源包时,可以将其卸载 或获取其引用,并在它存在于内存中时避免将其下载。可根据需求决定需要采取的相应措施,但我们建议在加载完对象后立即卸载该资源包 (AssetBundle)。这可释放内存空间,并且不会再收到有关加载已缓存资源包 (AssetBundles) 的错误。
如需跟踪已下载资源包 (AssetBundles),可使用包装类协助管理下载,如下:
uAssetBundleManager 类是静态的,正在引用的任何资源包 (AssetBundles) 不会在加载新场景时销毁。请将此类当做指南例程,但正如最初建议的那样,最好在使用后立即卸载资源包 (AssetBundles)。您始终可以克隆之前实例化的对象,无需再下载该资源包 (AssetBundles)。