Problem to upgrade BuildPipeline.BuildAssetBundle
Sup guys,
I'm trying to update my project from Unity 4 to version 5, I'm just having trouble now to update the BuildAssetBundle, I read the new document, but found it too abstract for understanding.
Could someone help me to update the code? And explain if possible?
Thank you very much!
static void ExportAssetBundles(){
string path = AssetDatabase.GetAssetPath(Selection.activeObject);
BuildAssetBundleOptions option = BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets;
if(path.Length !=0 )
{
path = path.Replace("Assets/","");
string [] fileEntries = Directory.GetFiles(Application.dataPath + "/" + path);
foreach(string fileName in fileEntries){
string filePath = fileName;
int index = filePath.LastIndexOf("/");
filePath = filePath.Substring(index);
int indexp = path.LastIndexOf("/");
path = path.Substring(0,indexp);
string localPath = "Assets/" + path;
if(index > 0)
{
localPath += filePath;
}
Object t =AssetDatabase.LoadMainAssetAtPath(localPath);
if(t != null)
{
string bundlepath = "Assets/" + path + "/" +t.name + ".unity3d";
BuildPipeline.BuildAssetBundle(t,null,bundlepath, option);
}
}
}
}
Comment
private static void ExportAssetBundles()
{
var path = AssetDatabase.GetAssetPath(Selection.activeObject);
if (path.Length == 0) return;
path = path.Replace("Assets/", string.Empty);
var fileEntries = Directory.GetFiles(Application.dataPath + "/" + path);
foreach (var fileName in fileEntries)
{
var filePath = fileName;
var index = filePath.LastIndexOf("/", StringComparison.Ordinal);
filePath = filePath.Substring(index);
var indexp = path.LastIndexOf("/", StringComparison.Ordinal);
path = path.Substring(0, indexp);
var localPath = "Assets/" + path;
if (index > 0) localPath += filePath;
var t = AssetDatabase.Load$$anonymous$$ainAssetAtPath(localPath);
if (t == null) continue;
var bundlepath = "Assets/" + path + "/" + t.name + ".unity3d";
var builds = new AssetBundleBuild[1];
builds[0] = new AssetBundleBuild
{
assetBundleName = t.name,
assetNames = new[] { bundlepath }
};
BuildPipeline.BuildAssetBundles(
bundlepath,
builds,
BuildAssetBundleOptions.None,
BuildTarget.StandaloneWindows);
}
}