using System.Collections.Generic; using System.IO; using UnityEngine; namespace MetaCity.BundleKit.Editor { public static class PrefabCollector { public static void CollectPrefabBundles(List tasks, List skipPrefabs) { DoCollectPrefabByFolder(tasks, Constants.ExportedAssetFolder, true, skipPrefabs); DoCollectPrefabByFolder(tasks, Constants.ImportedAssetFolder, false, skipPrefabs); } public static List CollectPrefabEntries() { DirectoryInfo dir = new DirectoryInfo(Constants.ExportedAssetFolder); var bundleNames = new List(); if (!dir.Exists) { return bundleNames; } foreach (var subDir in dir.GetDirectories()) { var bundleName = Utilities.CreateAssetBundleName(subDir.Name); bundleNames.Add(bundleName); } return bundleNames; } public static void DoCollectAssetsInFolder(List resourcePaths, string folderPath) { DirectoryInfo dir = new DirectoryInfo(folderPath); foreach (var fileInfo in dir.GetFiles()) { if (fileInfo.FullName.EndsWith(".meta")) { continue; } resourcePaths.Add(Path.Combine("Assets", Path.GetRelativePath(Application.dataPath, fileInfo.FullName))); } foreach (var subDir in dir.GetDirectories()) { DoCollectAssetsInFolder(resourcePaths, subDir.FullName); } } private static void DoCollectPrefabByFolder(List tasks, string rootFolder, bool needUpload, List skipPrefabs) { DirectoryInfo dir = new DirectoryInfo(rootFolder); if (!dir.Exists) { return; } foreach (var subDir in dir.GetDirectories()) { var resourcePaths = new List(); var bundleName = subDir.Name; if (skipPrefabs.Contains(Utilities.CreateAssetBundleName(bundleName))) { continue; } DoCollectAssetsInFolder(resourcePaths, subDir.FullName); var builder = Utilities.CreateNewAssetBundleBuild(bundleName, resourcePaths.ToArray()); tasks.Add(new MetacityBundle { BundleBuild = builder, BundleType = MetacityBundleType.Prefab, NeedUpload = needUpload }); } } } }