/// <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); } }
public static void BuildSpritesData() { SpritesData data = null; string folderPath = EditorUtils.GetSelectedDirAssetsPath(); string spriteDataPath = folderPath + "SpritesData.asset"; data = AssetDatabase.LoadAssetAtPath <SpritesData>(spriteDataPath); if (data == null) { data = ScriptableObject.CreateInstance <SpritesData>(); data.atlasName = folderPath; AssetDatabase.CreateAsset(data, spriteDataPath); } data.ClearAllSprites(); string workPath = EditorUtils.AssetsPath2ABSPath(folderPath); var filePaths = Directory.GetFiles(workPath); for (int i = 0; i < filePaths.Length; ++i) { string relPath = EditorUtils.ABSPath2AssetsPath(filePaths[i]); UnityEngine.Object[] objs = AssetDatabase.LoadAllAssetsAtPath(relPath); if (objs != null) { for (int j = 0; j < objs.Length; ++j) { if (objs[j] is Sprite) { data.AddSprite(objs[j] as Sprite); } else if (objs[j] is Texture2D) { ProcessSpriteTextureImport(relPath, folderPath); } } } } EditorUtility.SetDirty(data); AssetDatabase.SaveAssets(); Log.i("Success Process SpriteImport:" + folderPath); }
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); }
private static void BuildAssetBundlesInFolder(string folderPath) { if (folderPath == null) { Log.W("Folder Path Is Null."); return; } Log.I("Start Build AssetBundle:" + folderPath); var fullFolderPath = EditorUtils.AssetsPath2ABSPath(folderPath); //EditUtils.GetFullPath4AssetsPath(folderPath); var 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>(); foreach (var filePath in filePaths) { if (!filePath.EndsWith(".meta")) { continue; } var fileName = Path.GetFileName(filePath); 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(QFrameworkSettingData.EDITOR_AB_EXPORT_ROOT_FOLDER, new AssetBundleBuild[1] { abb }, BuildAssetBundleOptions.ChunkBasedCompression, BuildTarget.StandaloneWindows); }