Assetbundle建立與載入

來源:互聯網
上載者:User

標籤:des   style   blog   http   color   io   ar   使用   for   

【Assetbundle建立與載入】

  Unity有兩種動態載入機制:一種是Resource.Load。一種是AssetBundle。Assetbundle是Unity Pro提供的功能,它可以把多個遊戲對象或者資源二進位檔案封裝到Assetbundle中。供載入、解壓使用。  

【建立Assetbundle】

使用方法 BuildPipeline.BuildAssetBundle (Object, assets , pathName , options , targetPlatform) 

參數1:它只能放一個對象。

參數2:可以放入一個數組對象。

參數3:儲存路徑。

參數4:BuilderAssetBundleOptions

       CollectDependencies // 包含所有依賴關係。

       CompleteAssets//強制包含整個資源

       DisableWriteTypeTree//在資源套件不包含類型資訊。

       DeterministicAssetBundle//編譯資源套件使用一個雜湊表儲存對象ID在資源套件中。

       UncompressedAssetBundle//不壓縮Assetbundle,預設會進行壓縮

參數5:平台

       特別注意的是,電腦上和手機上打出來的Assetbundle不能混用,不同平台只能用自己的。

【載入Assetbundle】

       使用方法:

       1)WWW bundle = new WWW(path);

       2)WWW bundle = WWW.LoadFromCacheOrDownload(path, fileVer);

載入成功後就可以通過資源名使用bundle.assetBundle.Load方法擷取資源。

       如所示

  

  使用Assetbundle.Load會從Assetbundle的記憶體鏡像中讀取並建立一個Asset對象,建立的同時會分配相應的記憶體用於還原序列化儲存。

【記憶體釋放】

  

  最後在使用Assetbundle時候最好的方式是。

  建立時:使用Assetbundle.load載入所需的asset,載入完後立即Assetbundle.Unload(false),釋放Assetbundle檔案本身的記憶體鏡像,但不銷毀載入的Asset對象。這樣遍可以釋放一部分記憶體。

  釋放時。如果是通過Instantiate的對象,用Destroy進行銷毀。在合適的地方使用Resources.UnloadUnusedAssets,釋放已經沒有引用的Asset。Unity底層會對對象引用進行計數,如果引用為0.執行UnloadUnusedAssets就可以全部釋放。

 

Assetbundle建立與載入

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.