Unity3D, unity3d Official Website

Source: Internet
Author: User

Unity3D, unity3d Official Website

Unity's resource management has never been summarized, and all of them are on-demand documents. Someone asked me today that I did not answer the question. I said that I have also made two Unity games. Here, we will summarize and deepen our understanding of Unity resource management. Refer to Resources and AssetBundle in the official Unity documentation.

Unity has two ways to dynamically Load Resources: Resources. Load and AssetBundle. Resources. Load is used to Load Resources in the Resources directory of the game package. AssetBundle is used to Load the resource packages that you own outside the package (using BuildPipeline. BuildAssetBundle), which is often used for dynamic updates. The following describes the specific APIs:

Load:

Resources. Load: loads an asset in the Resources/directory of the app package;

Resources. LoadAsync: Asynchronous Method of Resources. Load;

Resources. LoadAll: similar to Resources. Load, but used to Load all assets in a directory;

Resources. LoadAssetAtPath: it is convenient to load Resources under the Asset/directory, but it can only be used in editor mode. It may be used when writing a packaging tool;

AssetBundle. CreateFromFile: load an AssetBundle from the disk. This is the fastest way to load AssetBundle. (I have found that this method can only be used for pc. This restriction is not provided in the official documentation and is to be verified );

AssetBundle. CreateFromMemory: creates an AssetBundle from the memory, asynchronous method;

AssetBundle. CreateFromMemoryImmediate: AssetBundle. CreateFromMemory synchronization method;

AssetBundle. LoadAsset: load an asset from AssetBundle;

AssetBundle. LoadAssetAsync: AssetBundle. LoadAsset asynchronous method;

AssetBundle. LoadAllAssets: loads all specified types of assets in AssetBundle;

AssetBundle. LoadAllAssetsAsync: AssetBundle. LoadAllAssets asynchronous method;

WWW. LoadFromCacheOrDownload: loads AssetBundle after downloading from the cache or on the network, without worrying about insufficient device space;


Uninstall:

Resources. UnloadAsset (Object assetToUnload): detach a specified asset, which can only be used to load data from a disk. If there is a reference to this asset in the scenario, Unity will automatically reload it;

Resources. UnloadUnusedAssets: unmounts all unreferenced assets, which can be called during screen switching or timed calls to release unused Resources globally;

AssetBundle. Unload (false): unmount the compressed file data (File Memory image) of AssetBundle );

AssetBundle. Unload (true): uninstall the memory image of the AssetBundle file and release all loaded assets. If the asset is referenced in the scenario, it will be lost;

Object. Destroy: Destroy a GameObject, component, or asset. instead of destroying it immediately, Destroy it before rendering after the Update loop;

Object. DontDestroyOnLoad: indicates that an Object will not be destroyed during switching;

GC. Collect: forces the Garbage Collector to recycle memory immediately. It can be used as needed, such as switching screen call or timed call;


By looking at these API descriptions of Unity, you can clearly understand the dynamic resource management of Unity. The following figure shows a clearer picture:


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.