What is Assetbundle
In the production of many types of games, developers will consider a very important issue, that is, how to dynamically download and load the resources during the game run. As a result, the Unity engine introduced Assetbundle as a technology to meet the needs of developers.
Assetbundle is a file format that the Unity engine provides for user storage that can store any kind of resources that the unity engine can recognize, such as models, textures, audio, animations, and even the entire scene.
At the same time, Assetbundle can also contain the developer's custom binaries, just need to change the binary file extension to. bytes,unity engine can identify it as textasset, so it can be packaged into the Assetbundle file inside.
How to create a assetbundle
This interface is developed to package any type of asset in the editor into a assetbundle file. Buildpipeline.buildassetbundle (Null,null,null,null,null);
Parameters of the Buildassetbundle
| Parameters |
Explanatory notes |
| Mainasset |
Used to specify the primary resource in the Assetbundle file, which can be read directly through Assetbundle.mainasset |
| Assets |
Used to specify the resources contained in the Assetbundle file |
| PathName |
Used to specify the creation address of the Assetbundle file |
| Assetbundleoptions |
Used to specify the creation options for the Assetbundle file, collect dependencies and completeassets by default |
| TargetPlatform |
Used to specify the platform that the Assetbundle file is used for publishing |
Through this interface, developers can directly package one or several scenarios in the project as a assetbundle file in a streaming manner. Buildpipeline.buildstreamsceneassetbundle (Null,null,null);
Buildstreamedsceneassetbundle
| Parameters |
Explanatory notes |
| Levels |
Used to specify the scene name to be packaged into the Assetbundle file |
| Locationpath |
Used to specify the creation address of the Assetbundle file |
| Target |
Used to specify the publishing platform that the Assetbundle file is used for |
The interface function is the same as the Buildpipeline.buildassetbundle interface, but you can specify a custom name for each object when you create it buildpipeline.buildassetbundleexplicitassetnames (Null,null,null,null,null);
How to download Assetbundle
Non-caching mechanism
void Start () { startcoroutine ("Loadasset");} Public IEnumerator Loadasset () { www www = new www (URL); yield return www;}
Caching mechanism
void Start () { startcoroutine ("Loadasset");} Public IEnumerator Loadasset () { www www = WWW.LoadFromCacheOrDownload (URL, 5); yield return www;}
How to load Assetbundle
WWW.assetbundle Property
void Start () {startcoroutine ("Loadasset");} Public IEnumerator loadasset () {www www = www. Loadfromcacheordownload (URL, 5); yield return www;if (www.error! = null) {Debug.Log (www.error); return;} Assetbundle bundle = Www.assetBundle;}
Assetbundle.createfromfile method
void Start () {Assetbundle bundle = assetbundle.createfromfile (path);}
Assetbundle.createfrommemory
void Start () {startcoroutine ("Loadasset");} Public IEnumerator loadasset () {www www = www. Loadfromcacheordownload (URL, 5); yield return www;if (www.error! = null) {Debug.Log (www.error); return;} byte[] data = www.bytes; Assetbundle bundle = assetbundle.createfrommemory (data);}
Cond...
[Unity Assetbundle] Asset resource Processing