Unity's Assetbundle system is an extension of resource management, dynamic updates, web games, and resource downloads are based on the Assetbundle system. But it has to be said that the system is very disgusting and the pit is deep. As to how deep it is, please read this article: http://www.cnblogs.com/ybgame/p/3973177.html
The original assetbundle system needs to write a large piece of the exported code (buildpipeline), the novice will not do, the veteran will often be the pit. It is not really easy to properly handle the dependencies of resources to ensure that resources are intact without duplicating resources.
Unity5 the new Assetbundle system greatly simplifies this operation. When unity is packaged, it automatically handles dependencies and generates a. manifest file that describes the Assetbundle packet size, CRC validation, dependencies between packages, and so on, is a text file. When loading resources, unity automatically handles the loading of its dependent packages.
The packaged code is simplified to a function (it's not really necessary, because the process is fixed, and the inline menu option doesn't matter)
Buildpipeline.buildassetbundles (OutputPath);
Execute this function, it will automatically package all the Assetbundle in the project directory, the function is smart enough, it will only package the modified resources.
How do I add a assetbundle?
Very simply, there is an option at the bottom of the resource Properties window, where the Assetbundle name is set. It modifies the resource's corresponding. meta file to record the name. The name of the assetbundle is fixed to lowercase. In addition, each assetbundle can be set a variant, is actually a suffix, the actual assetbundle name will add this suffix. If you have a resource with the same name at different resolutions, you can use this to make a distinction.
I have a lot of model resources in hand, so I wrote a script to automatically traverse Prefab's meta file and add assetbundle names. One thing to keep in mind is that the. meta file appears to have permission problems, cannot be written directly, needs to be deleted from the original file, and then replaced with a new file:
#-*-coding:utf-8-*-import os, sys, Shutil; Ext_list = ['. Prefab.meta ', '. Png.meta ', '. Jpg.meta '];d EF doWork (PATH): For-root, dirs, files in Os.walk (path): For file in files:for ext in ext_list:if file.endswith (EXT): FullPath = Os.path.join (ro OT, file) FullPath = fullpath.replace (' \ \ ', '/') Prefabname = fullpath.replace (path, '); Prefabname = prefabname[:p refabname.find ('. ')] + '. Data '; FileData = []; fp = open (FullPath, ' R '); For line in Fp:if line.find (' assetbundlename: ')! = -1:filedata.append (' Assetbundlename: ' + prefabname.lower () + ' \ n '); Else:fileData.append (line); Fp.close (); # os.remove (FullPath); # return; FPW = open (FullPath + '. tmp ', ' W '); Fpw.writelines (FileData); Fpw.cLose (); Os.remove (FullPath) shutil.copy (FullPath + '. tmp ', FullPath); Os.remove (FullPath + '. tmp ') break;dowork (R ' assets/resources/prefab/') os.system (' PAUSE ')
C # Editor extensions (like Python code features, which one to use)
public class exportassetbundles:editor{//Set Assetbundle name (modify meta file) [MenuItem ("Tools/setassetbundlename")] St atic void Onsetassetbundlename () {Unityengine.object obj = selection.activeobject; String path = Assetdatabase.getassetpath (Selection.activeobject); string[] extlist = new string[] {". Prefab.meta", ". Png.meta", ". Jpg.meta", ". Tga.meta"}; Editorutil.walk (Path, extlist, dosetassetbundlename); Refresh Editor Assetdatabase.refresh (); Debug.Log ("Assetbundlename modification completed"); } static void Dosetassetbundlename (string path) {Path = path. Replace ("\ \", "/"); int index = path. IndexOf (Editorconfig.prefab_path); String relativepath = path. Substring (path. IndexOf (Editorconfig.prefab_path) + Editorconfig.prefab_path. Length); String prefabname = relativepath.substring (0, Relativepath.indexof ('. ')) + Editorconfig.assetbundle; StreamReader fs = new StreamReader (path); list<string> ret= new List<string> (); String line; while (line = fs. ReadLine ()) = null) {line = line. Replace ("\ n", ""); if (line. IndexOf ("Assetbundlename:")! =-1) {line = "Assetbundlename:" + prefabname.tolower (); } ret. ADD (line); } fs. Close (); File.delete (path); StreamWriter writer = new StreamWriter (path + ". tmp"); foreach (Var) in ret) {writer. WriteLine (each); } writer. Close (); File.Copy (Path + ". tmp", path); File.delete (Path + ". tmp"); } [MenuItem ("Tools/createassetbundle")] static void Oncreateassetbundle () {Buildpipeline.buildassetbundle S (editorconfig.output_path); Refresh Editor Assetdatabase.refresh (); Debug.Log ("Assetbundle packing complete"); }}
Unity5 new Assetbundle System usage experience