/// <summary>
/// 单独打包
///
/// 所有资源分开单独打包
/// </summary>
[UnityEditor.MenuItem("Version AssetsBundle Build/source single build assetsbundle")]
public static void VersionAssetsBundle()
{
//todo
//获取全路径
Object[] allassets = Selection.GetFiltered<Object>(SelectionMode.Assets);
string path = Application.dataPath + "/StreamingAssets";
foreach (Object item in allassets)
{
//单独打包的话不需要使用assetsbuildoptions,
BuildPipeline.BuildAssetBundles(path, BuildAssetBundleOptions.None, BuildTarget.Android);
Debug.Log(AssetDatabase.GetAssetPath(item));
}
AssetDatabase.Refresh();
}
单独打包是指
一个指定勒assetsname的物体则打进assetsname的包中
若有多个assetsname
则打多少个assetsname的ab包
--------------------------------------------------------------------分割线--------------------------------------------------------------------
/// <summary>
/// 统一打包
///
/// 将所有标识可以打包的ab打进一个ab包里边
/// </summary>
[UnityEditor.MenuItem("Version AssetsBundle Build/source deep build assetsbundle")]
public static void DeepVersionAssetsBundle()
{
AssetBundleBuild[] builds = new AssetBundleBuild[1];
Object[] objects = Selection.GetFiltered<Object>(SelectionMode.DeepAssets);
string[] allpath = new string[objects.Length];
for (int i = 0; i < objects.Length; i++)
{
allpath[i] = AssetDatabase.GetAssetPath(objects[i]);
Debug.Log(allpath[i]);
}
builds[0].assetNames = allpath;
builds[0].assetBundleName = objects[0].name;
BuildPipeline.BuildAssetBundles(Application.dataPath + "/StreamingAssets/", builds, BuildAssetBundleOptions.None, BuildTarget.Android);
AssetDatabase.Refresh();
}
统一打包是指将指定的物体缓存好路径
然后根据自己的需要
将缓存好的路径分别打进不同的ab包
这里需要明确一点是assetsbundlebuild需要两个必要参数
一个是assetNames,缓存好的需要打包的物体的路径
另一个是assetBundleName,ab包的名称
--------------------------------------------------------------------分割线--------------------------------------------------------------------
两种方式的区别是
一个是系统根据物体指定的assetsname进行打包
一个是自己制定好具体物体打进指定ab包