/// <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); } }