当前位置:网站首页>How to package AssetBundle
How to package AssetBundle
2022-07-27 15:14:00 【A fool is a little proud】
AssetBundle What is it? ?
AssetBundle It's a Archive file , contain Can be loaded at runtime Of Platform specific Resources for ( Model 、 texture 、 The precast body 、 scene )
AssetBundle Sure Express the dependency between each other ,AssetBundle A Materials in can reference AssetBundle B Texture in
For effective delivery through the network , You can choose built-in algorithm to compress according to the requirements of use cases (LZMA,LZ4)
LZMA Algorithm : The compressed package is smaller , Longer load time . You need to decompress the whole before using . Once decompressed , This package will use LZ4 Recompress . At this time make There is no need to decompress the whole resource .
LZ4 Algorithm : The loading time is similar to that without compression , There is no need to decompress the whole before use .
1. For downloadable content , Reduce the initial installation size .
2. Load resources optimized for the end-user platform , Reduce memory pressure when running
3. Need to update some simple things , Such as festival activities UI It needs to be changed , have access to AssetBundle Package to update without requiring users to download the game again
AssetBundle What's in it ?
Contains the actual files on the disk , be called AssetBundle The archive , It can be regarded as a container , You can include other files . These documents fall into two categories :
1.serialized file( Serialized files ): Resources are broken up and placed in an object , Finally, the unification is written into a separate file ( only one )
resource files( Source file ): Resource files are just for some resources ( texture , Audio ) Separately stored binary data blocks , Allows us to effectively load them from disk on another thread
2.AssetBundle object : Objects loaded from a specific compressed package through code , This object contains all the contents that we originally added to this compressed package , We can use this object to load and use
AssetBundle Usage flow :
1. Of a specified resource AssetBundle attribute
In the resources to be packaged Inspector Specified in the panel AssetBundle Properties of
2. structure AssetBundle package
establish Editor Folder , Create one in the folder C# Script , The code is :
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; using System.IO; public class CreateAssetBundles{ /*MenuItem Property allows you to add menu items to the main menu and the inspector context menu . This attribute turns any static function into a menu command . Only static functions can use this MenuItem attribute */ [MenuItem("Assets/Build AssetBundles")] static void BulidAllAssetBundles() { string dir = "AssetBundles"; if (Directory.Exists(dir) == false) Directory.CreateDirectory(dir); // The output path Package compression format Packaged to the platform BuildPipeline.BuildAssetBundles(dir, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows64); } }BuildAssetBundleOptions.None: Use LZMA Algorithm compression
BuildAssetBundleOptions.UncompressedAssetBundle: Uncompressed , Bao Da , Load fast BuildAssetBundleOptions.ChunkBasedCompression: Use LZ4 Compress
adopt MenuItem We are Unity Of Asset Options create Bulid AssetBundles Option calls this code to package resources into dir In the specified directory
We can see the package in the project file AssetBundles It's packed
After the game is released, you need AssetBundle Package on the server , Then we need to download the game from the server AssetBundle Load the package , Due to frequent debugging during development , We load the package locally
3. Locally, yes AssetBundle Load and use : Create an empty object mount script in the game scene , The content is :
using System.Collections; using System.Collections.Generic; using UnityEngine; public class LoadWallFormFile : MonoBehaviour { // Use this for initialization void Start () { //1. load AssetBundle AssetBundle ab = AssetBundle.LoadFromFile("AssetBundles/wall.dz"); //2. from AssetBundle Get the resource to load GameObject wallPrefab = ab.LoadAsset<GameObject>("Wall"); //3. Instantiate resources into the scene Instantiate(wallPrefab); } }In this way, we can see the things we packed before in the scene
AssetBundle Group strategy :
Of a specified resource AssetBundle Tags are actually a kind of classification of resources
1. Frequently updated resources are placed in a separate package , Separate from infrequently updated packages
2. Resources that need to be loaded at the same time ( Small resources ) In a bag
3. Resources shared by other packages are put in one package ( Reduce AB The size of the bag )
4. Two versions of the same resource can be distinguished by suffixesFor the third point , There are cases of how to package shared resources :
As shown in the figure, there is a sphere and cube, All use the name wood The material of
If we don't use dependency packaging , Then the situation on the left in the figure below will appear ,AB Bao Zhongwei sphere and cube In the packed file , It contains the same maps and materials , If we use the dependency packaging scheme on the right , You can optimize the size of the package
First of all, we will share the map and material AssetBundle Set to share
Again cube and sphere Set up one AssetBundle Properties of , Random names
Observe the files packaged again ,cube and sphere The file size of is very small ,share The size of is the largest
If there is no resource setting to be shared AssetBundle Label words , It will be packaged as shown in the figure below ,cube and sphere Both contain the same set of maps and materials
边栏推荐
猜你喜欢

LeetCode 面试题 17.21. 直方图的水量 双指针,单调栈/hard

Kubernetes CNI 分类/运行机制

基于FIFO IDT7202-12的数字存储示波器

Visual system design example (Halcon WinForm) -10. PLC communication

Finally, someone finished all the dynamic planning, linked list, binary tree and string required for the interview

于不确定中见“安全感” 沃尔沃2022年中问道

代码覆盖率统计神器-jacoco工具实战

对话框管理器第三章:创建控件
MOS管防止电源反接的原理

generic paradigm
随机推荐
What is the breakthrough point of digital transformation in the electronic manufacturing industry? Lean manufacturing is the key
【云享读书会第13期】多媒体处理工具 FFmpeg 工具集
数据仓库项目从来不是技术项目
谷歌团队推出新Transformer,优化全景分割方案|CVPR 2022
Principle of MOS tube to prevent reverse connection of power supply
关于 CMS 垃圾回收器,你真的懂了吗?
Wechat applet realizes music search page
修改frameworks资源文件如何单编
LeetCode 90. 子集 II 回溯/medium
Lua study notes
Web page table table, realizing rapid filtering
CAN总线的EMC设计方案
Notice of Nanshan District Civil Affairs Bureau on carrying out the grade evaluation of social organizations in Nanshan District in 2022
Jmeter录制接口自动化
网络设备硬核技术内幕 路由器篇 4 贾宝玉梦游太虚幻境(下)
一些二进制位操作
Kubernetes CNI classification / operation mechanism
《剑指Offer》 链表反转
网络设备硬核技术内幕 路由器篇 20 DPDK (五)
cap理论和base理论








