当前位置:网站首页>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
边栏推荐
- 多线程环境下CountDownLatch的用法
- Passive income: return to the original and safe two ways to earn
- ADB command (install APK package format: ADB install APK address package name on the computer)
- STM32 can communication filter setting problem
- Internship: compilation of other configuration classes
- LeetCode 74. 搜索二维矩阵 二分/medium
- HDU3117 Fibonacci Numbers【数学】
- 反射
- 基于stm32的数字示波器设计方案
- 于不确定中见“安全感” 沃尔沃2022年中问道
猜你喜欢
随机推荐
Unity最简洁的对象池实现
JUC(JMM、Volatile)
Stm32f103c8t6 drives ssd1306 0.96 "IIC OLED display under Arduino frame
数据仓库项目从来不是技术项目
网络设备硬核技术内幕 路由器篇 9 CISCO ASR9900拆解 (二)
Unity性能优化------渲染优化(GPU)之Occlusion culling(遮挡剔除)
一些二进制位操作
[ManageEngine] what is Siem
LeetCode 456. 132模式 单调栈/medium
Data warehouse project is never a technical project
网络设备硬核技术内幕 路由器篇 11 CISCO ASR9900拆解 (五)
internship:其他配置类的编写
网络设备硬核技术内幕 路由器篇 13 从鹿由器到路由器(上)
reflex
Lua study notes
两阶段提交与三阶段提交
移动端使用vantUI的list组件,多个tab项来回切换时,列表加载多次导致数据无法正常展示
什么是Tor?Tor浏览器更新有什么用?
Unity performance optimization ----- LOD (level of detail) of rendering optimization (GPU)
Principle of MOS tube to prevent reverse connection of power supply


















