Use assetbundle and unity3dassetbundle in Unity3d

Source: Internet
Author: User

Use assetbundle and unity3dassetbundle in Unity3d

1. Export assetbundle:

  ① Export a single resource to assetbundle;

② Export multiple resources into an assetbundle;

2. Read assetbundle:

  ① Load to memory;

② Decompress the package into a specific resource.

 

1. Export assetbundle:

  

① Export a single resource to assetbundle;

BuildPipeline. buildAssetBundle (Object obj, null, string path, BuildAssetBundleOptions. collectDependencies, BuildTarget. android); // obj a single resource, converted to the Object type // path (for example, "Assets/streamingassets/obj. unity3d "), the extension of the resource package can be arbitrarily written or not written // BuildAssetBundleOptions. collectDependencies contains resource dependencies. For example, if the source to be exported is a prefab, the referenced mesh, texture, material ball, and animation are all exported to the resource package. // BuildTarget. which platform is the resource package exported by Android, Android, PC, or others?


 

② Export multiple resources into an assetbundle;

BuildPipeline. buildAssetBundle (null, Object [] objs, string path, BuildAssetBundleOptions. collectDependencies, BuildTarget. android); // objs contains arrays of multiple resources, Object [] type // path (for example: "Assets/streamingassets/obj. unity3d "), the extension of the resource package can be arbitrarily written or not written // BuildAssetBundleOptions. collectDependencies contains resource dependencies. For example, if the source to be exported is a prefab, the referenced mesh, texture, material ball, and animation are all exported to the resource package. // BuildTarget. which platform is the resource package exported by Android, Android, PC, or others?

 

 

2. Read assetbundle:

  ① Load to memory;

② Decompress the package into a specific resource.

IEnumerator Load (string path, string name) {/* the process of loading to the memory */WWW bundle = new WWW (path); // example: "Assets/streamingassets/obj. unity3d "yield return bundle;/* the process of decompressing the package into a specific resource */Object obj = bundle. assetBundle. load (name); // name is the name of a specific resource}

 

 

Note:IEnumerator is a coroutine. It can be imagined as a multi-thread in Unity3d, which means that many things can be done at the same time. Although the principle is different from multithreading, the effect is almost no different. If you want to deal with assetbundle of many resources, whether it is imported into one or multiple resources, You Need To reasonably plan the coroutine organization based on the specific requirements of the planning.

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.