Unity explore the development of actual combat - loaded release resources best strategy brief experience

Unity explore the development of actual combat - loaded release resources best strategy brief experience

I also read an article about the release of Unity Resources essay "Unity explore the development of combat - the best strategy for resources loaded release" If you feel a little complicated, here are some of the more brief experiences:

General

Resource loading method commonly used in three ways: static, Resources internal resources, AssetBundle external resources

Resource release there are two ways: the immediate release and the release of unity.

Static state

Static is to direct resources to put scenes, static resources can not be released immediately, but the scene is closed unity released by the engine, developers can not intervene, so most no brain.

But still too rigid, in addition to the resources of the entire life cycle of a scene that must be used is not recommended static load, why, time-consuming, taking up memory; for example, the background music game scene continued use, static is indeed the best choice; but If you want to play back the opening scene of a 5M music is no longer used, this resource is static in vain to increase the loading time 5M 5M music and wasted memory, more harm than good.

Static resource loading strategy is: only load the necessary fixed resource, or tiny little loss of resources.

Release strategy is: the responsibility of the engine.

Resources internal resources

Resources resources in general and games packaged together, generally critical resources used within the game.

Resources major load some resources need to be flexible or dynamic processes. Load approach is to first Reources.Load, then GameObject.Instantiate, immediate release approach is Reources.UnloadAsset, unified approach is to release Resources.UnloadUnusedAssets.

The main advantage is the use of flexible Resources, the disadvantage is the development of complex; when loading the attention of a resource only once Reources.Load, good management Load out references to the resources, try not to use static references, make it difficult to release. Care must be taken to release all references before UnloadUnusedAssets, out of all Instantiate the object must be destroyed.

Resources load release strategy is: only load resources that must be used, after loading without having to re-use or frequency of use is very low, it should be clear in the future after use (such as pictures show ended, the music has finished playing) immediately with the release of Reources.UnloadAsset . Resources for the follow-up will still be repeatedly used, referenced in the cache memory is recommended in order to prevent subsequent loads are no longer called repeatedly Load function, freeing the cache before the scene closed, destroy all instances of objects, waiting Resources.UnloadUnusedAssets unified release. UnloadUnusedAssets release is recommended after the current scene is completely destroyed, and then follow-up the implementation of the most secure in the scene.

AssetBundle external resources

 The basic mechanism AssetBundle resources and Resources similar, but can be independently packaged support network to download and read the file, usually a secondary resource used in the game.

 AssetBundle mechanism than Resources multi-step, first by AssetBundle.LoadFromXXX the AssetBundle loaded into memory and then use AssetBundle.LoadAsset loading resources, and finally GameObject.Instantiate to instantiate the object. So there is a complete instantiation of AssetBundle memory references three, relatively complex on the release strategy.

 AssetBundle release function mainly through AssetBundle.Unload, but also can be used Reources.UnloadAsset and Resources.UnloadUnusedAssets be released.

 AssetBundle load release strategy two cases:

After calling the resource package is loaded after no longer need to be re-loaded at once AssetBundle.Unload (false) to release memory resources package, and on this basis, and no longer used for future AssetBundle.LoadAsset resources can Reources .UnloadAsset release. For continued use, it could wait Resources.UnloadUnusedAssets follow unified release.

After the completion of loading the resource package still need to continue to use, you must retain AssetBundle reference, in this way, comparing the proposed approach is completely destroyed at a later scene, a one-time call AssetBundle.Unload (true) complete release change package and all of its resources load resources.

Guess you like

Origin www.cnblogs.com/zergcom/p/11066510.html