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.