Game Development Reference
In-Depth Information
To make an AssetBundle, select all the assets in the Project panel to be included in
the bundle and then go to Assets | Build AssetBundle from Selection from the
menu bar. Once selected, choose a location on your computer where the bundle
should be saved.
Selecting assets to be included in an AssetBundle
Then, to test the AssetBundle, create a new project or open a different project
without the assets, and you can load them into your project at runtime using the
WWW class. See the following code sample 10-3 for a sample script that downloads
an AssetBundle from a local file, extracts a texture asset, and assigns it to the
material of an attached mesh renderer component:
using UnityEngine;
using System.Collections;
public class LoadAssetBundle : MonoBehaviour
{
//Mesh Renderer Reference
private MeshRenderer MR = null;
// Use this for initialization
IEnumerator Start ()
{
//Get asset bundle file from local machine
WWW www = new WWW (@"file:///c:\asset_textures.unity3d");
//Wait until load is completed
yield return www;
//Retrieve texture from asset bundle
Texture2D Tex = www.assetBundle.Load
("texture_wood",typeof(Texture2D)) as Texture2D;
//Assign texture in bundle to mesh
MR = GetComponent<MeshRenderer>();
MR.material.mainTexture = Tex;
}
}
 
Search WWH ::




Custom Search