Version: 2022.2
言語: 日本語
アセットバンドル用のアセットの準備
アセットバンドルの依存性

アセットバンドルのビルド

Note: This section describes the creation of AssetBundles using the built-in BuildPipeline.BuildAssetBundles() API. A recommended, and more user friendly, alternative is to use the Addressables package.

In the documentation on the AssetBundle Workflow, we have a code sample which passes three arguments to the BuildPipeline.BuildAssetBundles function. Let’s dive a little deeper into what we’re actually saying.

Assets/AssetBundles は、AssetBundle (アセットバンドル) の出力先ディレクトリです。これを任意のディレクトリに変更することができます。そのフォルダーはビルドを始める前にすでに存在するフォルダーでなければなりません。

BuildAssetBundleOptions

BuildAssetBundleOptions は数種類あり、様々な効果を指定することができます。すべてのオプションの表は、スクリプトリファレンスの BuildAssetBundleOptions を参照してください。

必要に応じて自由に BuildAssetBundleOptions を組み合わせることができますが、AssetBundle (アセットバンドル) の圧縮に関しては、3 つの特定の BuildAssetBundleOptions があります。

  • BuildAssetBundleOptions.None:このバンドルオプションでは LZMA 形式の圧縮を使用します。これはシリアライズされたデータファイルから成る 1つの圧縮 LZMA ストリームです。LZMA 圧縮では、バンドル全体が使用前に解凍されている必要があります。これにより、ファイルサイズは最小限に抑えられますが、圧縮解凍のためのロード時間が若干長くなります。この BuildAssetBundleOptions を使用する場合、バンドルからアセットを使用するには、バンドル全体を最初に圧縮解除する必要があることに注意してください。
    一旦バンドルが解凍されると、バンドルからアセットを使用する前に、バンドル全体を解凍する必要がない LZ4 圧縮を使用してディスク上で再圧縮されます。これは、バンドルがから1 つのアセットを使用する場合に、すべてのアセットがロードされるようなアセットが含まれている場合に最適です。キャラクターやシーンのすべてのアセットのパッケージ化を行う場合に、この方法を使用すると良い場合があります。
    LZMA 圧縮を使用するのは、ファイルサイズが小さいため、オフサイトのホストからアセットバンドルを最初にダウンロードする場合にのみ推奨されます。 UnityWebRequestAssetBundle を通してロードされた LZMA 圧縮アセットバンドルは自動的に LZ4 圧縮に再圧縮され、ローカルファイルシステムにキャッシュされます。バンドルを他の方法でダウンロードして保存する場合は、AssetBundle.RecompressAssetBundleAsync APIを使用してバンドルを再圧縮できます。

  • BuildAssetBundleOptions.UncompressedAssetBundle: このバンドルオプションでは、データをまったく圧縮しないでバンドルをビルドします。圧縮しない不利な点は、ファイルのダウンロードサイズが大きくなることです。しかし、いったんダウンロードが終わると、読み込み時間はずっと早くなります。非圧縮のアセットバンドルは 16 バイトに揃えられています。

  • BuildAssetBundleOptions.ChunkBasedCompression: このバンドルオプションでは、LZ4 という圧縮方法を使用します。LZ4 ではファイルの圧縮サイズは LZMA より大きくなります。しかし、LZMA と異なり、使用前にバンドル全体を解凍する必要がありません。LZ4 では、「かたまり」に基づいたアルゴリズムを使用し、アセットバンドルを部分的、もしくは、かたまりごとに読み込むことが可能です。1 つのかたまりを解凍すると、たとえアセットバンドルの他のかたまりが解凍されていなくても、解凍したかたまりに含まれるアセットは使用することができます。

ChunkBasedCompression を使うことで、ディスク上のサイズを縮小できるという利点に加え、圧縮されていないバンドルと同等の読み込み時間を実現します。

BuildTarget

BuildTarget.Standalone: これにより、アセットバンドルをどのターゲットプラットフォームに使用するかをビルドパイプラインに指示します。スクリプトリファレンスの BuildTarget に可能なビルドターゲットが明記してあるリストがあります。ただし、ビルドターゲットをハードコードしたくない場合は、EditorUserBuildSettings.activeBuildTarget の利用も便利です。これを使うと、ビルドのターゲットとなる現在設定されているプラットフォームを自動的に検知し、そのターゲットに基づいてアセットバンドルをビルドします。

適切にビルドスクリプトを設定したら、最後にバンドルをビルドします。Assets > Build AssetBundles の順に選び処理を始めます。

Now that you’ve successfully built your AssetBundles, you may notice that your AssetBundles directory has more files than you might have originally expected. 2*(n+1) more files, to be exact. Let’s take a minute and go over exactly what the BuildPipeline.BuildAssetBundles call yields.

エディターで指定したアセットバンドルにはすべて、アセットバンドルと同じ名のファイルと、アセットバンドル名 + “.manifest” というファイルがあります。

There will be an additional bundle and manifest that doesn’t share a name with any AssetBundle you created. It, instead, is named after the directory that it’s located in (where the AssetBundles were built to). This is the Manifest Bundle. This bundle contains the AssetBundleManifest object which will be useful for figuring out which bundle dependencies to load at runtime. To learn more about how to use this bundle and the manifest object, see documentation on Using AssetBundles Natively.

AssetBundle ファイル

AssetBundle (アセットバンドル) ファイルには .manifest の拡張子がなく、アセットをロードするためにランタイムにロードします。

アセットバンドルファイルは複数のファイルを内部に持つアーカイブです。このアーカイブの構造は、それがアセットバンドルなのかシーンのアセットバンドルなのかによって、多少変わります。以下は通常のアセットバンドルの構造です。

シーンのアセットバンドルは通常のアセットバンドルと異なり、シーンとそのコンテンツのストリームのロードのために最適化されています。

Manifest ファイル

For every bundle generated, including the additional Manifest Bundle, an associated manifest file is generated. The manifest file has the extension .manifest and can be opened with any text editor. It contains information such as the cyclic redundancy check (CRC) data and dependency data for the bundle. The manifest files for normal AssetBundles will look something like this:

ManifestFileVersion: 0
CRC: 2422268106
Hashes:
  AssetFileHash:
    serializedVersion: 2
    Hash: 8b6db55a2344f068cf8a9be0a662ba15
  TypeTreeHash:
    serializedVersion: 2
    Hash: 37ad974993dbaa77485dd2a0c38f347a
HashAppended: 0
ClassTypes:
- Class: 91
  Script: {instanceID: 0}
Assets:
  Asset_0: Assets/Mecanim/StateMachine.controller
Dependencies: {}

これには含まれるアセット、依存関係、その他の情報が示されています。

A manifest file is also generated for the Manifest Bundle. It will look like this:

ManifestFileVersion: 0
AssetBundleManifest:
  AssetBundleInfos:
    Info_0:
      Name: scene1assetbundle
      Dependencies: {}

This file records how AssetBundles relate, and what their dependencies are. This is similar to the information recorded by the AssetBundleManifest object, inside the Manifest Bundle, and because it is a text file it is convenient for human readability and parsing by external tools.

アセットバンドル用のアセットの準備
アセットバンドルの依存性
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961