Resources directory of Unity resources

introduce

Store assets in one or more folders named Resources, and use the Resources API to load or unload objects from those assets at runtime.


Best Practices for Resources System

don't use it

This strong recommendation is made for several reasons:

Use the Resources folder to make fine-grained memory management more difficult

Improper use of resource folders can increase application startup and build times

As the number of Resources folders increases, it becomes very difficult to manage Assets in these folders

The resource system reduces the ability of projects to deliver custom content to specific platforms and removes the possibility of incremental content upgrades

AssetBundle Variants is Unity's primary tool for adapting content to each device


Use the resource system correctly

There are two specific use cases where the resource system can help without hindering good development practices:

1. The ease of use of the Resources folder makes it an excellent system for rapid prototyping. However, the Resources folder should be eliminated when the project enters full production.

2. The Resources folder may be useful in some trivial cases, if the content is:
a. Usually required throughout the life of the project
b. Does not take up memory
c. Not easy to patch, or will not vary by platform or device Varies
d. for minimal bootstrap

Examples of the second case include MonoBehaviour singletons for hosting prefabs, or ScriptableObjects containing third-party configuration data such as Facebook application IDs.

Resources serialization

  When building the project, assets and objects from all folders named "Resources" are combined into one serialization file. The file also contains metadata and index information, similar to an AssetBundle. As described in the AssetBundle documentation, the index includes a serialized lookup tree used to resolve the name of a given object to its appropriate file GUID and local ID. It is also used to locate objects at specific byte offsets within the body of the serialized file.

  On most platforms, the lookup data structure is a balanced search tree whose construction time grows in O(n log(n)). This growth also causes the load time of the index to grow super-linearly as the number of objects in the resource folder increases.

  This action is not skippable and occurs when the application starts, with the initial non-interactive splash screen displayed. Initializing a resource system with 10,000 assets has been observed to take seconds on low-end mobile devices, although in practice it is rarely necessary to load most of the objects contained in the resource folder into the application's first scene.

Guess you like

Origin blog.csdn.net/a_codecat/article/details/128523215