您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
82 行
2.8 KiB
82 行
2.8 KiB
using System.Collections.Generic;
|
|
using System.IO;
|
|
using UnityEngine;
|
|
|
|
namespace MetaCity.BundleKit.Editor
|
|
{
|
|
public static class PrefabCollector
|
|
{
|
|
public static void CollectPrefabBundles(List<MetacityBundle> tasks, List<string> skipPrefabs)
|
|
{
|
|
DoCollectPrefabByFolder(tasks, Constants.ExportedAssetFolder, true, skipPrefabs);
|
|
DoCollectPrefabByFolder(tasks, Constants.ImportedAssetFolder, false, skipPrefabs);
|
|
}
|
|
|
|
public static List<string> CollectPrefabEntries()
|
|
{
|
|
DirectoryInfo dir = new DirectoryInfo(Constants.ExportedAssetFolder);
|
|
var bundleNames = new List<string>();
|
|
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<string> 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<MetacityBundle> tasks, string rootFolder, bool needUpload, List<string> skipPrefabs)
|
|
{
|
|
DirectoryInfo dir = new DirectoryInfo(rootFolder);
|
|
if (!dir.Exists)
|
|
{
|
|
return;
|
|
}
|
|
|
|
foreach (var subDir in dir.GetDirectories())
|
|
{
|
|
var resourcePaths = new List<string>();
|
|
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
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|