以前也在用unity商店里的AssetBundles-Browser-master插件打包,觉得比较繁琐,有这个一键打包就方便多了。
using UnityEngine;
using UnityEditor;
public class AssetsBundle
{
[MenuItem("Assets/打包选中的资源(.PC)")]
static void PrefabsBuilding ()
{
Object[] selection = Selection.GetFiltered(typeof(Object),SelectionMode.DeepAssets);
if (selection.Length <= 0)
return;
string path = EditorUtility.SaveFilePanel("另存为",Application.streamingAssetsPath+"/data",selection[0].name,"dat");
if(path.Length != 0)
{
BuildPipeline.BuildAssetBundle(Selection.activeObject,selection,path,BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets,BuildTarget.StandaloneWindows);
Debug.Log("PC .dat文件导出完成");
}
}
[MenuItem("Assets/打包选中的资源(.Android)")]
static void AndroBuilding ()
{
Object[] selection = Selection.GetFiltered(typeof(Object),SelectionMode.DeepAssets);
if (selection.Length <= 0)
return;
string path = EditorUtility.SaveFilePanel("另存为",Application.streamingAssetsPath+"/data",selection[0].name,"dat");
if(path.Length != 0)
{
BuildPipeline.BuildAssetBundle(Selection.activeObject,selection,path,BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets,BuildTarget.Android);
Debug.Log("Android .dat文件导出完成");
}
}
[MenuItem("Assets/打包选中的资源(.IOS)")]
static void IOSBuilding ()
{
Object[] selection = Selection.GetFiltered(typeof(Object),SelectionMode.DeepAssets);
if (selection.Length <= 0)
return;
string path = EditorUtility.SaveFilePanel("另存为", Application.streamingAssetsPath + "/data", selection[0].name, "dat");
if(path.Length != 0)
{
BuildPipeline.BuildAssetBundle(Selection.activeObject,selection,path,BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets,BuildTarget.iOS);
Debug.Log("IOS .dat文件导出完成");
}
}
}