AssetBundle.Unload 卸载

function Unload (unloadAllLoadedObjects : bool) : void

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中加载的物体也将被销毁。如果场景中有游戏物体引用该资源,那么引用也会丢失。

引用至jesse_luzexi的博客:

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

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

最后修改:2010年12月15日 Wednesday 17:49

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。