在创建 AssetBundle 时使用基于块的 LZ4 压缩。
当使用基于块的压缩时,AssetBundle 的内容将被分解成单独的段,这些段将使用CompressionType.Lz4HC 算法独立压缩。生成的档案通常比默认使用的完整文件压缩更大,但使用这种格式构建的 AssetBundle 可以增量加载,例如,无需将完整内容解压缩到内存中。这是 AssetBundle 缓存中存储的 AssetBundle 使用的默认格式。
其他资源:AssetBundles 压缩,BuildCompression,CompressionType,ArchiveHandle.Compression,Caching,BuildAssetBundleOptions.UncompressedAssetBundle,BuildOptions.CompressWithLz4。
//Create a folder (right click in the Assets folder and go to Create>Folder), and name it “Editor” if it doesn’t already exist //Place this script in the Editor folder
//This script creates a new Menu named “Build Asset” and new options within the menu named “Normal” and “Chunk Based Compression”. Click these menu items to build an AssetBundle.
using UnityEngine; using UnityEditor;
public class Example { //Creates a new menu (Build Asset Bundles) and item (Normal) in the Editor [MenuItem("Build Asset Bundles/Normal")] static void BuildABsNone() { //Build AssetBundles with no special options //They will be written in the custom folder ("MyAssetBuilds") which needs to exist prior to this call. BuildPipeline.BuildAssetBundles("Assets/MyAssetBuilds", BuildAssetBundleOptions.None, BuildTarget.StandaloneOSX); }
//Creates a new item (Chunk Based Compression) in the new Build Asset Bundles menu [MenuItem("Build Asset Bundles/Chunk Based Compression")] static void BuildABsChunk() { //Build the AssetBundles in this mode BuildPipeline.BuildAssetBundles("Assets/MyAssetBuilds", BuildAssetBundleOptions.ChunkBasedCompression, BuildTarget.StandaloneOSX); } }