Unity Game FrameWork—Framework Learning—Ab Packaging Process Analysis

UGF resource update and management
https://www.jianshu.com/p/80bff8c9004a

Package configuration

The ResourceBuilder.xml file saves the packaging configuration information
[picture]
parameters:
InternalResourceVersion: internal version number
Platforms: the platform number corresponding to the generated ab resource, binary left shift, AND or non operation to obtain
AssetBundleCompression: compression format label, no compression, LZ4 compression, LZMA compression
CompressionHelperTypeName: Compression and decompression helper type name
AdditionalCompressionSelected: Whether to perform recompression to reduce transmission overhead
ForceRebuildAssetBundleSelected: Whether to force the rebuilding of AssetBundle
BuildEventHandlerTypeName: Related event class type name for building ab
OutputDirectory: ab output folder, other output directories are derived from this directory
OutputPackageSelected: Whether to generate package resources
OutputFullSelected: Whether to generate full resources
OutputPackedSelected: Whether to generate Packed resources
Explanation of each directory:
Working: The working directory when Unity generates AssetBundle.
Package: The directory where the files generated for stand-alone mode are located. If the game is a stand-alone game, after the generation is completed, copy the files corresponding to the platform in this directory to StreamingAssets and then build the App.
Full:The directory where the complete file package generated for the updateable mode is located. If the game is an online game, after the generation is completed, this directory should be uploaded to the resource server for players to download.
Packed: The directory where the files generated in the updateable mode are located. If the game is an online game, after the generation is completed, copy the files corresponding to the platform in this directory to StreamingAssets and then build the App. Whether an AssetBundle will be generated to the Output Packed Path depends on whether the AssetBundle is marked as Packed in the AssetBundle editing tool. (Resources released with the APP are stored in this directory)
BuildReport: AB package and non-AB package files are uniformly abstracted into Resource files in GF, and the file suffix is ​​.dat. In our resource list, the records are It is the resource information of these .dat resource files. The information includes the name of these resource files, hashcode, length, zipHashcode, zip length, whether it is an AB package, loading settings, and other information.

Packaging process

The packaged process execution starts by pressing the Start Build Resources button
[picture]
. Find the ResourceBuilder script. When the button is clicked and the value of the bool type variable m_OrderBuildResources changes to true, the BuildResources() method
private void Update()
{ if (m_OrderBuildResources) { m_OrderBuildResources = false; BuildResources(); } }





Class relationship
The creation relationship of the class is as follows
ResourceBuilder: Resource generator (entry)
ResourceBuilderController: Resource construction controller
ResourceAnalyzerController: Resource analysis controller
ResourceCollection: Resource collection
Resource: Resource information contained in ab package
Asset: Resource file information
// Resource generator ( Entry)
ResourceBuilder: EditorWindow
{ private ResourceBuilderController m_Controller = null; } //Resource construction controller ResourceBuilderController { The number of resource files contained in ab package 127 private readonly ResourceCollection m_ResourceCollection; private readonly ResourceAnalyzerController m_ResourceAnalyzerController; //Full path of ab resource - ab package information Key-value pairs, number of ab packages 116 private readonly SortedDictionary<string, ResourceData> m_ResourceDatas; }











//Resource analysis controller
ResourceAnalyzerController
{ private readonly ResourceCollection m_ResourceCollection; //The resources on which each resource file depends private readonly Dictionary<string, DependencyData> m_DependencyDatas; //Each dependent resource (a) corresponds to the resource that depends on it The list formed by resources (b, c), (b, c) belongs to the resources in the ab package private readonly Dictionary<string, List> m_ScatteredAssets; //A list of all dependencies after ab resources and scattered resources are integrated private readonly List< string[]> m_CircularDependencyDatas; //Dependency resource list (ab + scattered), unordered collection, fast search, no duplication private readonly HashSet m_AnalyzedStamps; } //Resource collection ResourceCollection { //ab path-ab resource Resource information key value Right (116) private readonly SortedDictionary<string, Resource> m_Resources; //guid-Assets key-value pair (127)
















private readonly SortedDictionary<string, Asset> m_Assets;
}
//The resource information contained in the ab package
Resource
{ private readonly List m_Assets;//The resource files contained in the ab package private readonly List m_ResourceGroups;//The resource group to which it belongs public string Name //ab Package name public string Variant //Variant name public string FullName //Full name, including path public AssetType AssetType //Resource type, resource or scene public bool IsLoadFromBinary //Whether to load from a binary file public string FileSystem public LoadType LoadType //Resource Loading method type public bool Packed //Whether it is the main package resource } //Resource file information Asset: IComparable { public string Guid;//Resource file guid public string Name;//Resource file name public Resource Resource;//Ab package to which it belongs

















}
//Dependency data information
public sealed class DependencyData
{ //The ab package it depends on private List m_DependencyResources; //The files in the ab package it depends on private List m_DependencyAssets; //The scattered file names it depends on private List m_ScatteredDependencyAssetNames; } / /Dependency information //Each resource file may have multiple dependent files. The resource file in the ab package has as many dependencies as there are structures. struct Stamp { private readonly string m_HostAssetName;//Resource file name private readonly string m_DependencyAssetName;//Dependent resource file name } The entrance is the ResourceBuilderController.BuildResources() method. The main process is as follows: 1. Create a file system and generate ab resource folders for each mode. 2. Set ab resource generation options BuildAssetBundleOptions buildAssetBundleOptions = GetBuildAssetBundleOptions ();



















3. Collect resource information
m_ResourceCollection.Load()
reads the resource information xml file (Assets/GameMain/Configs/ResourceCollection.xml)
and obtains the resource information that needs to be packaged from the ResourceCollection.xml file and fills it into m_Resources and m_Assets of the ResourceCollection class. The ResourceCollection class is composed of ResourceBuilderController creation
4. Analyze dependent resources
Analyze
m_ResourceAnalyzerController.Analyze();
The ResourceAnalyzerController class is created by ResourceBuilderController. ResourceAnalyzerController's m_ResourceCollection resource data comes from ResourceBuilderController.
This step mainly fills in the attribute information of ResourceAnalyzerController m_DependencyDatas
[picture]Insert image description here
List<string[]> m_CircularDependencyDatas= new List<string[]>();
m_CircularDependencyDatas[0]=new string[]{a,b,d,c,b}
m_CircularDependencyDatas[1 ]=new string[]{b,d,c,b}
m_CircularDependencyDatas[2]=new string[]{c,b,d,c}
m_CircularDependencyDatas[3]=new string[]{e,f,h,e}
m_CircularDependencyDatas[4]=new string[]{f,h,e,f}
m_CircularDependencyDatas[5]=new string[]{h,e, f, h}
If only a and e are in the ab package, then all other dependent b, c, d, f, h, k will also be counted. 5. Prepare to
build the data of ab resource
PrepareBuildData (out assetBundleBuildDatas, out assetBundleResourceDatas, out binaryResourceDatas)
Note that only assetBundleBuildDatas is the data required by the editor to export AssetsBundle. The data is obtained from ResourceBuilderController.m_ResourceCollection and does not directly depend on the analysis of resources in the previous step. The data generated by analyzing resources is displayed in the analysis in order to be more intuitive. device panel. In other words, the analysis results do not process resources. This step can

6. Build resources for the selected platform
BuildResources(Platform.Windows, assetBundleBuildDatas, buildAssetBundleOptions, assetBundleResourceDatas, binaryResourceDatas);
building resources is divided into three steps
. 1. Generate resource files and resource and resource list files (i.e. files named after the generation path, Windows and Windows.manifest)
AssetBundleManifest assetBundleManifest = BuildPipeline.BuildAssetBundles(workingPath, assetBundleBuildDatas, buildAssetBundleOptions, GetBuildTarget(platform));
Use assetBundleBuildDatas data to generate ab resources, in the working directory
[picture]
2. Output the encrypted ab package and byte stream The key functions of the check code
are as follows, find
ProcessAssetBundle(platform, workingPath, outputPackagePath, outputFullPath, outputPackedPath, AdditionalCompressionSelected, assetBundleResourceDatas[i].Name, assetBundleResourceDatas[i].Variant, assetBundleResourceDatas[i].FileSystem) by yourself)
ProcessOutput(platform, outputPackagePath, outputFullPath, outputPackedPath, additionalCompressionSelected, name, variant, fileSystem, resourceData, bytes, length, hashCode, compressedLength, compressedHashCode) 3. Output the encrypted list files under each platform ProcessPackageVersionList(outputPackagePath, platform);
ProcessReadOnlyVersionList
(
outputPackedPath , platform);

ab resource loading

DefaultLoadResourceAgentHelper
///
/// Starts asynchronous reading of resource files by loading the resource agent helper.
///
/// The full pathname of the resource to be loaded.
public override void ReadFile(string fullPath)
{ if (m_LoadResourceAgentHelperReadFileCompleteEventHandler == null || m_LoadResourceAgentHelperUpdateEventHandler == null || m_LoadResourceAgentHelperErrorEventHandler == null) { Log.Fatal("Load resource agent helper handler is invalid."); return; }




        m_FileFullPath = fullPath;
        //将本地资源加载到内存
        m_FileAssetBundleCreateRequest = AssetBundle.LoadFromFileAsync(fullPath);
    }

ab build analysis

After studying the source code, I benefited a lot. The analysis of resources in ab construction is very complete. Resource updates use incremental updates. Developers do not need to pay attention to what content has been updated. The records of resource content are packaged separately, which is very friendly.
After the resource analysis is completed, we may face two problems if the project does not manage resources well.
The same bulk file that each ab package depends on will be copied and packaged into each ab package multiple times. Is it possible to consider providing guidance on how to classify and package the analysis interface, and repeat the common bulk resources to be packaged separately to reduce resource redundancy.
It is said that the yooasset and MotionFramework frameworks handle redundancy very well. We need to continue to study and research. Here are the links.
https://zhuanlan.zhihu.com/p/615830582

Guess you like

Origin blog.csdn.net/qq_37619255/article/details/133304039