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