Go into the details of design unity Resource Management

I. Summary

This article talk about how Unity is managed based on the manner in which, based on the management approach, how planning and resource management, and building bundle, is the need for a detailed discussion later.

Two, Unity of resource management

2.1 resource classification

unity project resources, resources can be divided into external and internal generating introducing both types of resources.
Import External Resources:  most of the resources generated art, are brought into external resources, models, textures, UI-use map is basically the art tools to generate, imported into the project.
Generating internal resources:  Part art to generate a resource, such as material, Shader, special effects, scenes, etc., are generated based on the Unity engine to produce, in addition to various prefab (UI / characters, etc.), and code script (c # based), are also Unity internal generation of resources.

2.2 storage resource

After engineering resources into unity, will convert stored in various ways, are the following:

2.2.1 script resource category

For the project script class resources, and non-plugin plugin divided into two categories.

  • plugin class: plugin reference in the dll, generate their own associated dll, when the final construct game pieces, the game is driven into the relevant package:      
  • Non plugin class: Unity builds into four basic dll, built for the sequence:
    • Assembly-CSharp-firstpass: standard assets/Pro standard assets/plugins 中的脚本
    • Assembly-CSharp-Editor-firstpass: editor scripts in standard assets / Pro standard assets / plugins this dll will not be driven into the game packages, are under specific editor dll
    • Assembly-CSharp: all other scripts that not inside editor main game logic dll
    • Assembly-CSharp-Editor: all remaing scripts inside editor of this dll will not be driven into the game packages, editor-specific dll

All final package built into the game dll, divided into:

  • Assembly-CSharp.dll / Assembly-CSharp-firstpass.dll these two main game logic dll
  • Engine and plug-referenced dll dll

2.2.2 Fine Arts Resources

Fine Arts resources are divided into external and internally generated introducing two categories

  • External introducing categories: Scene / model / mapping can be introduced into an external
    • After inherited from AssetPostprocesser, may be related modifications are performed on the import of textures, materials, models, scenes
  • Internally generated class: shader / material / prefab / art scene can be generated resources of internal resources and special effects textures resources, are the focus of concern, will go into the details behind the management of these resources
    • Ibid modification operations

2.2.3 meta file

After a good division of engineering resources, how to manage these resources? Different engines have different management style, then unity is how to manage?
Meta and generates a sequence of file: here management is divided into two steps

2.2.3.1 unity of serialized

Engineering resources, to be stored in a local disk, it will be by-step sequence of the engine operation, the sequence of the essence, the object is to be converted into a binary resource files in a certain order.

2.2.3.2 meta file generation

After completing the sequence of, unity will generate a file for the corresponding meta file, this file will follow the meta file has always existed, if you delete the resource file, the corresponding meta file will be automatically deleted engine.
meta file is mainly composed of:

  • Guid file: unique index id whole project in this document, based on the id, you can find the corresponding file. guid generation of nature, is the path to convert file-based generation, the same token, if the merger occur when multiple projects guid conflict, can regenerate yourself a guid, related links: https://gist.github.com / ZimM-LostPolygon / 7e2f8a3e5a1be183ac19 

  • Import settings file:

    • For general files, import settings are relatively simple script class called MonoImporter, resource called NativeFormatImporter
    • Maps belonging to need to focus on the type of import type called TextureImporter, which sets out the detailed set of detailed information on the various compression formats, mipmaps, type, uv, size, and so the texture map

2.2.4 Based on meta file and serialized resource management

In addition to guid meta file, unity also generates a file for each resource id, which is fileID, but now fileID no longer remain in the meta file, and to retain the serialized file in the file for the resource, there will be a localID, this localID, corresponding to that contain child resource in a resource when the resource used to locate each child:  

So how serialization is associated with a guid / fileID of?
In the internal unity project, if you add additional resources to the resource references, for example, add a script, drag an external reference, it will trigger a sequence of operations, fileID and guid serialization and it will be referenced resources We are serialized down, so that deserialization time, and will be based on fileID guid to find reverse-dependent resources to load in.   

This process, in Unity, the process is a load of, say one more thing, if the more dependent on other resources, a resource, then the loading process will be more time-consuming, so open a lot of UI when there is a part of the time consumed in the load on the various components of the UI.

Third, the summary

基于前文,可以对整个unity的资源管理有一个初步的认识,基于meta文件和序列化操作,可以管理工程中的资源,同时也能管理好各个资源的互相引用,那么基于这样的设计,在构建bundle的时候,是可以进行相关的设计和实现的。

Guess you like

Origin www.cnblogs.com/zblade/p/11089050.html