1. Export. Unity3d format resources:
Http://game.ceeger.com/Script/BuildPipeline/BuildPipeline.BuildAssetBundle.html
Here I have changed a little bit ~~~ The Code is as follows:
Using unityengine; using unityeditor; using system. io; public class buildassetbundlesfromdirectory {[@ menuitem ("asset/build assetbundles from directory of Files")] Static void exportassetbundles () {// get the selected directory // obtain the selected directory string Path = assetdatabase. getassetpath (selection. activeobject); debug. log ("selected folder:" + path); If (path. length! = 0) {Path = path. replace ("assets/", ""); string [] fileentries = directory. getfiles (application. datapath + "/" + path); foreach (string filename in fileentries) {string filepath = filename. replace ("\", "/"); int Index = filepath. lastindexof ("/"); filepath = filepath. substring (index + 1); debug. log ("filepath:" + filepath); string localpath = "assets/" + path + "/"; if (index> 0) localpath + = filepath; object T = ASSE Tdatabase. loadmainassetatpath (localpath); If (T! = NULL) {debug. log (T. name); string bundlepath = "assets/" + path + "/" + T. name + ". unity3d "; debug. log ("Building bundle at:" + bundlepath); // build the resource file from the active selection. // compile the resource file buildpipeline from the activation selection. buildassetbundle (T, null, bundlepath, buildassetbundleoptions. completeassets );}}}}}
Note: String filepath = filename. Replace ("\", "/"); Convert "\" to "/". "Assets/path/. Prefab" and "path \. Prefab"
Put the script of the above Code in a folder, select the folder, and click "asset/build assetbundles from directory of Files" on the menu bar to convert it to unity3d format.
2. Load. unity3d:
function Start () {var www = new WWW ("file:///"+Application.dataPath+"/resourse/Cube.unity3d");yield www;Instantiate(www.assetBundle.mainAsset);}
Note: application. datapath obtains the resource path of the modified program.
function Start (){ var www = WWW.LoadFromCacheOrDownload("http://210.30.12.33:8080/YangChun/file/Cube.unity3d",5); yield www; if (www.error != null) { Debug.Log (www.error); return; } Instantiate(www.assetBundle.mainAsset);}
I tried to use the resources class to load unity3d files. However, if it is locally loaded, you can directly load the Prefab. You do not need to use the unity3d format. Looks like
The loadfromcacheordownload method can only load files in the. unity3d format. I tested it with the Tomcat server to achieve the cache effect.
3. Load the scenario:
First, convert the scenario to unity3d format.
Note: The scripts of the following code must be placed in the Editor folder (if the file is not changed, create a new one). Note that buildtarget is converted to different platforms ~~~ Buildtarget. andrdoid
@MenuItem ("Build/BuildWebplayerStreamed")static function MyBuild(){var levels : String[] = ["Assets/yaya.unity"];BuildPipeline.BuildStreamedSceneAssetBundle( levels, "yaya.unity3d", BuildTarget.WebPlayer);//BuildTarget.Andrdoid}
Or
@MenuItem ("Build/BuildWebplayerStreamed")static function MyBuild(){BuildPipeline.BuildPlayer(["Assets/main.unity"],"VR.unity3d",BuildTarget.WebPlayer, BuildOptions.BuildAdditionalStreamedScenes); }
Function start () {// download compressed scene. if version 5 of the file named "Streamed-Level1.unity3d" was previusly downloaded and cached. // then unity will completely skip the download and load the decompressed scene directly from disk. // download compression scenario. If the file version named Streamed-Level1.unity3d is 5, pre-download and cache. // Then, unity will skip the download and directly load and decompress the package from the disk. VaR download = www. loadfromcacheordownload ("http: // 210.30.12.16: 8080/chunge/Yaya. unity3d", 5); yield download; // handle errorif (download. Error! = NULL) {debug. logerror (download. error); return;} // in order to make the scene available from loadlevel, We have to load the asset bundle. // The assetbundle class also lets you force unload all assets and file storage once it is no longer needed. // to make the scenario loadlevel available, you must load the resource package // assetbundle class, and you can force Uninstall all resources and file storage. VaR bundle = download. assetbundle; // load the level we have just downloaded // load the downloaded level application. loadlevel ("Yaya"); // The "Yaya" here refers to "assets/Yaya. unity, instead of Yaya. unity3d "}