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的情況了。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM