Unity5.1 Assetbundle

Source: Internet
Author: User

Resource Management Scripts

1 usingSystem;2 usingSystem.Collections;3 usingSystem.Collections.Generic;4 usingUnityengine;5 usingUnityeditor;6 7 8 namespaceLoasset9 {Ten      Public classLoassetmanager One     { A          PublicLoassetmanager () -         { -  the         } -  -         /// <summary> -         ///Handling Packages +         /// </summary> -         /// <param name= "AB" ></param> +         /// <param name= "name" ></param> A          Public Static voidProcessassetbundle (Assetbundle AB,stringname) at         { -             //get all the resources an array group -             string[] All_asset_names =AB. Getallassetnames (); -  -             //get all the scene an array groups -             string[] All_scene_names =AB. Getallscenepaths (); in  -             if(!Teststringarray (all_asset_names)) to             { +Debug.Log ("no assets."); -             } the  *             if(!Teststringarray (all_scene_names)) $             {Panax NotoginsengDebug.Log ("no scenes."); -             } the  +             //get the configuration file for the entire Assetbundle folder AAssetbundlemanifest manifest = ab. Loadasset<assetbundlemanifest> ("assetbundlemanifest"); the  +             //Get -             string[] All_bundles =manifest. Getallassetbundles (); $  $             if(!Teststringarray (all_asset_names)) -             { -Debug.Log ("no bundles."); the             } -         }Wuyi  the         /// <summary> -         ///test function Wu         /// </summary> -         /// <param name= "names" ></param> About         /// <returns></returns> $          Public Static BOOLTeststringarray (string[] names) -         { -             if(Names = =NULL) -             { A                 return false; +             } the  -             foreach(stringIteminchnames) $             { the Debug.Log (item); the             } the             return true; the         } -     } in}

Test scripts

1 usingUnityengine;2 usingSystem.Collections;3 usingLoasset;4 5  Public classTestscript:monobehaviour6 {7     /// <summary>8     ///Download the resource bundle9     /// </summary>Ten     /// <returns></returns> One IEnumerator downloadassetbundle () A     { -         //Access Address Header -         stringURL ="http://project.lanou3g.com/assetbundles/Others/"; the  -         //Access Resource Name -         stringRoot ="Others"; -  +         //constructs access to WWW objects -WWW Root_url =NewWWW (URL +root); +  A         yield returnRoot_url; at  -         //when the download is complete, get Assetbundle -Assetbundle Rootbundle =Root_url.assetbundle; -  -         //Processing bundles ... - Loassetmanager.processassetbundle (Rootbundle, root); in  -         //Cube resource's name "Prefabs/cube.prefab" to         stringCube ="Prefabs/cube.prefab"; +  -         //Constructing Access Objects theWWW Cube_url =NewWWW (URL +cube); *  $         yield returnCube_url;Panax Notoginseng  -Assetbundle Cubebundle =Cube_url.assetbundle; the  +         //Load Resources ... AGameobject prefab = cubebundle.loadasset<gameobject> ("Mycube.prefab"); the  +Gameobject Gameobject =gameobject.instantiate (prefab); -  $GameObject.transform.position =NewVector3 (0,0,0); $     } -  -     //Use this for initialization the     voidStart () { -         //start loading process ...WuyiStartcoroutine ("Downloadassetbundle"); the     } -      Wu     //Update is called once per frame -     voidUpdate () { About      $     } -}

Unity5.1 Assetbundle

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.