/// <summary> // 递归处理文件夹下所有Asset 文件 /// </summary> /// <param name="folderPath">Asset目录下文件夹</param> private static void AutoGenAssetNameInFolder(string folderPath, bool useFolderName) { if (folderPath == null) { Log.w("Folder Path Is Null!"); return; } Log.i("Start Set Asset Name. Folder:" + folderPath); string workPath = EditorUtils.AssetsPath2ABSPath(folderPath); //EditUtils.GetFullPath4AssetsPath(folderPath); string assetBundleName = EditorUtils.AssetPath2ReltivePath(folderPath).ToLower(); //EditUtils.GetReltivePath4AssetPath(folderPath).ToLower(); assetBundleName = assetBundleName.Replace("resources/", ""); //处理文件 var filePaths = Directory.GetFiles(workPath); for (int i = 0; i < filePaths.Length; ++i) { if (!AssetFileFilter.IsAsset(filePaths[i])) { continue; } string fileName = Path.GetFileName(filePaths[i]); string fullFileName = string.Format("{0}/{1}", folderPath, fileName); AssetImporter ai = AssetImporter.GetAtPath(fullFileName); if (ai == null) { Log.e("Not Find Asset:" + fullFileName); return; } else { if (useFolderName) { ai.assetBundleName = assetBundleName; } else { ai.assetBundleName = string.Format("{0}/{1}", assetBundleName, PathHelper.FileNameWithoutSuffix(fileName)); } } //ai.SaveAndReimport(); //Log.i("Success Process Asset:" + fileName); } //递归处理文件夹 var dirs = Directory.GetDirectories(workPath); for (int i = 0; i < dirs.Length; ++i) { string fileName = Path.GetFileName(dirs[i]); fileName = string.Format("{0}/{1}", folderPath, fileName); AutoGenAssetNameInFolder(fileName, useFolderName); } }
private static void BuildAssetBundlesInFolder(string folderPath) { if (folderPath == null) { Log.w("Folder Path Is Null."); return; } Log.i("Start Build AssetBundle:" + folderPath); string fullFolderPath = EditorUtils.AssetsPath2ABSPath(folderPath); //EditUtils.GetFullPath4AssetsPath(folderPath); string assetBundleName = EditorUtils.AssetPath2ReltivePath(folderPath); // EditUtils.GetReltivePath4AssetPath(folderPath); var filePaths = Directory.GetFiles(fullFolderPath); AssetBundleBuild abb = new AssetBundleBuild(); abb.assetBundleName = assetBundleName; List <string> fileNameList = new List <string>(); for (int i = 0; i < filePaths.Length; ++i) { if (!AssetFileFilter.IsAsset(filePaths[i])) { continue; } string fileName = Path.GetFileName(filePaths[i]); fileName = string.Format("{0}/{1}", folderPath, fileName); fileNameList.Add(fileName); } if (fileNameList.Count <= 0) { Log.w("Not Find Asset In Folder:" + folderPath); return; } abb.assetNames = fileNameList.ToArray(); BuildPipeline.BuildAssetBundles(ProjectPathConfigTemp.EXPORT_ROOT_FOLDER, new AssetBundleBuild[1] { abb }, BuildAssetBundleOptions.ChunkBasedCompression, BuildTarget.StandaloneWindows); }