AssetBundle中Unload()方法的作用

AssetBundle.Unload(false)的作用:

官网的解释是这样的:

When unloadAllLoadedObjects is false, compressed file data for assets inside the bundle will be unloaded

说是当参数是false时,会释放掉assetbundle里面的关于资源的压缩文件数据。

AssetBundle.Unload 卸载

Description描述

Unloads all assets in the bundle.

卸载所有包含在bundle中的对象。

Unload frees all the memory associated with the objects inside the bundle.

When unloadAllLoadedObjects is false, compressed file data for assets inside the bundle will be unloaded, but any actual objects already loaded from this bundle will be kept intact. Of course you won't be able to load any more objects from this bundle.

When unloadAllLoadedObjects is true, all objects that were loaded from this bundle will be destroyed as well. If there are game objects in your scene referencing those assets, the references to them will become missing.

卸载释放bundle中所有序列化数据。当unloadAllLoaderObjects为假,bundle内的序列化数据将被释放,但是任何从这个bundle中实例化的物体都将完好。当然,你不能从这个bundle中加载更多物体。当unloadAllLoaderObjects为真,所有从该bundle中加载的物体也将被销毁。如果场景中有游戏物体引用该资源,那么引用也会丢失。

总结:

1.参数为false时,bundle内的序列化数据将被释放,但是任何从这个bundle中实例化的物体都将完好,所以不能从这个bundle中加载更多物体
2.参数为true时,所有从该bundle中加载的物体也将被销毁,如果场景中有物体引用该资源,引用会丢失

所以应该是assetbundle在Load资源的时候,不仅会把需要资源Load到内存中,同时还会生成一份数据在内存中,这部分数据记录着关于该资源的一些数据(应该也保存着该资源的引用),那么下次Load该资源时,首先会查找有没有关于该资源的数据,有的话说明该资源已经加载到内存中了,直接返回该资源的引用

引用至jesse_luzexi的博客:

这是U3D没有处理好的一个环节。在WWW加载资源完毕后,对资源进行instantiate后,对其资源进行unload,这时问题就发生 了,instantiate处理渲染需要一定的时间,虽然很短,但也是需要1,2帧的时间。此时进行unload会对资源渲染造成影响,以至于没有贴图或 者等等问题发生。

解决办法:
自己写个时间等待代码,最好不要用WaitForSeconds,U3D的API,这个东西很撮,恶心死我了。。。
我估计它这个类写的有问题,检查了好长时间,最后还是自己写了几行代码来替换这个类,解决了问题。
等待个0.5秒到1秒之后再进行Unload。这样就不会出现instantiate渲染中就运行unload的情况了。

 

posted @ 2017-05-10 19:45  AaronBlogs  阅读(5490)  评论(0编辑  收藏  举报