unity实现按文件夹自动打包assetbundle
Posted 左右...
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了unity实现按文件夹自动打包assetbundle相关的知识,希望对你有一定的参考价值。
直接上源码,功能:选中文件下所有带_ab的文件夹分为一个ab包,自动命名打包
public class EDxAssetBundle : MonoBehaviour
//[MenuItem("Tool/Create AssetBundle All")]
//private static void CreateAssetBundle()
//
// Debug.Log("Create AssetBundle...");
// BuildPipeline.BuildAssetBundles(Application.streamingAssetsPath + "/assetbundle", BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows64);
// AssetDatabase.Refresh();
//
[MenuItem("Tool/Create AssetBunldes")]
[System.Obsolete]
private static void CreateAssetBunldesMain()
//获取在Project视图中选择的所有游戏对象
Object[] SelectedAsset = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
//遍历所有的游戏对象
foreach (Object obj in SelectedAsset)
string sourcePath = AssetDatabase.GetAssetPath(obj);
string filename = GetFileName(sourcePath);
string parentname = GetParentName(sourcePath);
//Debug.Log(obj.name + " : " + sourcePath);
if (!string.IsNullOrEmpty(filename))
Debug.Log("打包 " + obj.name + " : " + sourcePath);
AssetImporter ai = AssetImporter.GetAtPath(sourcePath);
if (ai.assetBundleName != parentname + ".assetbundle")
ai.assetBundleName = parentname + ".assetbundle";
string path = Application.streamingAssetsPath + "/assetbundle";
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
BuildPipeline.BuildAssetBundles(Application.streamingAssetsPath + "/assetbundle", BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows64);
//刷新编辑器
AssetDatabase.Refresh();
private static string GetParentName(string path)
string[] strs = path.Split('/');
//string parent = strs[strs.Length - 2];
for (int i = 0; i < strs.Length; i++)
if (strs[i].Contains("_ab")) return strs[i];
return "";
private static string GetFileName(string path)
string[] strs = path.Split('/');
string filename = strs[strs.Length - 1];
if (filename.Contains("."))
return filename;
else
return "";
工程地址:https://download.csdn.net/download/u014261855/13099912
以上是关于unity实现按文件夹自动打包assetbundle的主要内容,如果未能解决你的问题,请参考以下文章