Unity3d-Resource Management

Source: Internet
Author: User

There has been no summary of Unity's resource management, which is the accompanying documentation. Today someone asked, unexpectedly did not answer up, said also did two unity game, ashamed. Summarize here to deepen your understanding of unity resource management. The main reference is the resources and assetbundle of the official unity document.

Unity has two different ways of dynamically loading resources,resources.load and assetbundle. Resources.load is used to load the resources under the resource directory in the game pack, Assetbundle is used to load the resource bundle (using Buildpipeline.buildassetbundle) outside the package and is often used for dynamic updates. The following combination of API specific instructions:

Load:

Resources.load: Load a asset of the resources/directory within the app package;

Resources.loadasync: asynchronous method of Resources.load;

Resources.loadall: Similar to Resources.load, but used to load all asset in a directory;

Resources.loadassetatpath: Loading the resources under the asset/directory is convenient, but it can only be used in the editor mode, which may be used when writing the packaging tool;

Assetbundle.createfromfile: Loading a assetbundlefrom disk, which is the fastest way to load assetbundle (I found someone saying this way can only be used for PCs, The official documentation does not mention this limitation, pending inspection);

Assetbundle.createfrommemory: Create a Assetbundle, asynchronous method from memory;

synchronization method of AssetBundle.CreateFromMemoryImmediate:AssetBundle.CreateFromMemory;

Assetbundle.loadasset: Loading a asset from the Assetbundle;

asynchronous method of AssetBundle.LoadAssetAsync:AssetBundle.LoadAsset;

Assetbundle.loadallassets: Loads all asset of the specified type in the Assetbundle;

asynchronous method of AssetBundle.LoadAllAssetsAsync:AssetBundle.LoadAllAssets;

WWW.LoadFromCacheOrDownload: Load assetbundle After downloading from cache or network, no need to worry about lack of device space;


Unloading:

Resources.unloadasset (Object assettounload): Unloads the specified asset and can only be used to load from disk; If there is a reference to this asset in the scene, unity will reload it automatically;

Resources.unloadunusedassets: Uninstall all unreferenced asset, can be called when the screen switch, or the scheduled call to release the global unused resources;

Assetbundle.unload (false): Uninstalls Assetbundle Compressed file data (file memory image);

Assetbundle. Unload (True) : unmount the assetbundle file memory image and release all loaded asset; If asset is referenced in the scene, it will be lost;

Object.destroy: Destroying a gameobject, component, or asset; not immediately destroyed, but after the update loop, before rendering;

Object.dontdestroyonload: Indicates that an object is not destroyed when switching scenes;

Gc. Collect: Force the garbage collector to reclaim memory immediately, can be used as needed, such as switch screen call or timed call;


By looking at these API descriptions from unity, you can clearly understand the dynamic resource management of unity. The following diagram depicts a clearer picture:


Unity3d-Resource Management

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.