using UnityEngine; using System.Collections; using UnityEditor; //(1)
public class BuildAssetBundles{
[MenuItem ("Assets/Auto Build Image File")]
public static void buildImage(){
BuildPipeline.PushAssetDependencies();
BuildAssetBundleOptions options = BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets;
Object[] asset = new Object[1];
asset[0] = AssetDatabase.LoadMainAssetAtPath("Assets/Resources/pic1.png");
BuildPipeline.BuildAssetBundle(null, asset, "Textures.unity3d", options);
BuildPipeline.PopAssetDependencies(); }
}
the code build a Textures.unity3d.but read the texture is wrong ?
WWW www = new WWW ("file:///"+Application.dataPath+"/Resources/Textures.unity3d"); yield return www; if(www.isDone) { Texture t=Instantiate(www.assetBundle.Load("pic1"))as Texture; //Instantiating a non-readable 'Bucket2' texture is not allowed! Please mark the texture readable in the inspector or don't instantiate it. }
How to read the texture?