Version: 2022.3
言語: 日本語
アセットバンドルを使いこなす
アセットバンドルにパッチを適用する

アセットバンドルの圧縮

Use this page to learn about the AssetBundle compression formats and cache types that Unity supports.

AssetBundle compression formats

デフォルトでは、Unity は LZMA 圧縮でアセットバンドルを作成し、LZ4 圧縮でそれらをキャッシュします。ここでは、両方の圧縮形式について説明します。

Unity’s AssetBundle build pipeline creates AssetBundles with LZMA compression. This compression format is a stream of data representing the entire AssetBundle, which means that if you need to read an Asset from these archives, you must decompress the entire stream. This is the preferred format for AssetBundles downloaded from a Content Delivery Network (CDN), because the file sizes are smaller than those with LZ4 compression.

LZ4 compression is a chunk-based compression algorithm. If Unity needs to access an Asset from an LZ4 archive, it only needs to decompress and read the chunks that contain bytes of the requested Asset. This is the compression method that Unity uses in both of its AssetBundle caches. Use the BuildAssetBundleOptions.ChunkBasedCompression value when building AssetBundles to force LZ4(HC) compression.

Uncompressed AssetBundles that Unity builds when you use BuildAssetBundleOptions.UncompressedAssetBundle require no decompression, but occupy more disk space. Uncompressed AssetBundles are 16-byte aligned.

AssetBundle cache

To optimize the fetching, recompressing, and versioning of LZMA AssetBundles using WWW or UnityWebRequest (UWR), Unity maintains two caches:

  • The Memory Cache stores AssetBundles in UncompressedRuntime format in RAM.

  • ディスクキャッシュ は、取得したアセットバンドルを、後述する圧縮形式で書き込み可能なメディアに保存します。

メモリキャッシュにロードされたアセットバンドルは大量のメモリを消費します。アセットバンドルのコンテンツに頻繁かつ迅速にアクセスしたい場合を除いて、メモリキャッシュはメモリコストに見合わないでしょう。代わりに、ディスクキャッシュを使用してください。

If you provide a version parameter to the UWR API, Unity stores your AssetBundle data in the Disk Cache. If you don’t provide a version parameter, Unity uses the Memory Cache. The version parameter can be either a version number or a hash. If Caching.compressionEnabled is set to true, Unity applies LZ4 compression when it writes AssetBundles to disk for all subsequent downloads. It doesn’t compress existing uncompressed data in the cache. If Caching.compressionEnabled is false, Unity applies no compression when it writes AssetBundles to disk.

アーカイブを目的の形式に再圧縮する必要があるため、キャッシュされた LZMA アセットバンドルを最初にロードするのに長い時間がかかります。それ以降のロードでは、キャッシュされたバージョンが使用されます。

AssetBundle.LoadFromFile or AssetBundle.LoadFromFileAsync always use the Memory Cache for LZMA AssetBundles, so you should use the UWR API. If it’s not possible to use the UWR API, you can use AssetBundle.RecompressAssetBundleAsync to rewrite an LZMA AssetBundle on disk.

Note: WebGL doesn’t support LZMA compression for AssetBundles. Use LZ4 compression with AssetBundles on WebGL platforms. For more information, see Reduce load times with AssetBundles.

Internal testing shows significant difference in RAM usage between using the Disk Cache instead of the Memory Cache. You must weigh the trade-off between memory impact versus added disk space requirements and Asset instantiation time for your application.

アセットバンドルを使いこなす
アセットバンドルにパッチを適用する
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961