理解 AssetBundleBuild 字段 addressableNames & assetNames

AssetBundleBuild.assetNames identifies the exact location and name for bundling an asset. (assume buildMap is of type AssetBundleBuild)

buildMap[0].assetNames[0] = "Assets/Textures/stinky_pupper_smol.jpg";

AssetBundleBuild.addressableNames is an optional nickname for loading the asset its array index corresponds to.

buildMap[0].addressableNames[0] = "DogTexture";

That's all done during build time so during runtime you can load that texture like this (assume bundleis of type AssetBundle):

bundle.LoadAsset("DogTexture");

instead of:

bundle.LoadAsset("Assets/Textures/stinky_pupper_smol.jpg");

AssetBundleBuild.addressableNames 

Description

Addressable name used to load an asset.

To provide custom addressable names for assets in the bundle, this array needs to be the same size as AssetBundleBuild.assetNames. Each entry in this array will be matched to the asset in assetNames based on index. If the string in a given index in addressableNames is empty, the value in assetNames at the same index is used instead (default behaviour).

 

AssetBundleBuild.assetNames

public string[] assetNames;

Description

Asset names which belong to the given AssetBundle.

Please use the asset path relative to the project folder, for example "Assets/MyPrefab.prefab".

 

压缩格式
  (1)LZMA:默认压缩格式,压缩比大,省空间,使用前需要解压整个压缩包;
  (2)LZ4:5.3版本新增, 40%–60% 的压缩率,开启BuildAssetBundleOptions.ChunkBasedCompression打包参数即可。
    LZ4算法是“基于块”的,因此当对象从一个LZ4压缩包加载时,仅用于该对象的相应块会被解压,不需要解压整个包。
    所以LZ4和不压缩资源一样,都可以不解压,而直接读取包中的资源的。
  (3)UnCompress:不压缩,访问最快,费空间。
  一组测试数据:

LZMA:1.45M

LZ4:2M

UnCompress:4M

  LZ4格式压缩比还可以,而且加载速度也很快,是大多数情况下的最优解。

 

资源LOD
  一个资源可以设置两个标签,第一个参数assetBundleName 表示包的名字,第二个参数assetBundleVariant 用来做资源的LOD。
  假设本地有两套贴图资源,一套高清,一套普通,然后给他们设置同样的assetBundleName为MyAsset,高清资源的assetBundleVariant 设置为LD,普通资源设置为SD,那么就可以根据不同设备通过选择加载MyAsset.LD或MyAsset.SD来切换资源库,这样依赖MyAsset的Prefab就可以动态切换版本了。
  注意,两套资源集的asset必须完全一一对应,对于unity来说LD和SD是同一个bundld,同一时刻只能加载其中一个。

你可能感兴趣的:(Unity)