Update AssetBundleCollector

pull/51/head
hevinci 2022-10-19 15:52:16 +08:00
parent 5199430766
commit 8389ce5793
12 changed files with 150 additions and 25 deletions

View File

@ -132,10 +132,10 @@ namespace YooAsset.Editor
/// <summary>
/// 获取打包收集的资源文件
/// </summary>
public List<CollectAssetInfo> GetAllCollectAssets(EBuildMode buildMode, bool enableAddressable, AssetBundleCollectorGroup group)
public List<CollectAssetInfo> GetAllCollectAssets(CollectCommand command, AssetBundleCollectorGroup group)
{
// 注意:模拟构建模式下只收集主资源
if (buildMode == EBuildMode.SimulateBuild)
if (command.BuildMode == EBuildMode.SimulateBuild)
{
if (CollectorType != ECollectorType.MainAssetCollector)
return new List<CollectAssetInfo>();
@ -162,7 +162,7 @@ namespace YooAsset.Editor
{
if (result.ContainsKey(assetPath) == false)
{
var collectAssetInfo = CreateCollectAssetInfo(buildMode, group, assetPath, isRawAsset);
var collectAssetInfo = CreateCollectAssetInfo(command, group, assetPath, isRawAsset);
result.Add(assetPath, collectAssetInfo);
}
else
@ -177,7 +177,7 @@ namespace YooAsset.Editor
string assetPath = CollectPath;
if (IsValidateAsset(assetPath) && IsCollectAsset(assetPath))
{
var collectAssetInfo = CreateCollectAssetInfo(buildMode, group, assetPath, isRawAsset);
var collectAssetInfo = CreateCollectAssetInfo(command, group, assetPath, isRawAsset);
result.Add(assetPath, collectAssetInfo);
}
else
@ -187,7 +187,7 @@ namespace YooAsset.Editor
}
// 检测可寻址地址是否重复
if (enableAddressable)
if (command.EnableAddressable)
{
HashSet<string> adressTemper = new HashSet<string>();
foreach (var collectInfoPair in result)
@ -207,7 +207,7 @@ namespace YooAsset.Editor
return result.Values.ToList();
}
private CollectAssetInfo CreateCollectAssetInfo(EBuildMode buildMode, AssetBundleCollectorGroup group, string assetPath, bool isRawAsset)
private CollectAssetInfo CreateCollectAssetInfo(CollectCommand command, AssetBundleCollectorGroup group, string assetPath, bool isRawAsset)
{
string address = GetAddress(group, assetPath);
string bundleName = GetBundleName(group, assetPath);
@ -215,7 +215,7 @@ namespace YooAsset.Editor
CollectAssetInfo collectAssetInfo = new CollectAssetInfo(CollectorType, bundleName, address, assetPath, assetTags, isRawAsset);
// 注意:模拟构建模式下不需要收集依赖资源
if (buildMode == EBuildMode.SimulateBuild)
if (command.BuildMode == EBuildMode.SimulateBuild)
collectAssetInfo.DependAssets = new List<string>();
else
collectAssetInfo.DependAssets = GetAllDependencies(assetPath);

View File

@ -69,7 +69,7 @@ namespace YooAsset.Editor
/// <summary>
/// 获取打包收集的资源文件
/// </summary>
public List<CollectAssetInfo> GetAllCollectAssets(EBuildMode buildMode, bool enableAddressable)
public List<CollectAssetInfo> GetAllCollectAssets(CollectCommand command)
{
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000);
@ -83,7 +83,7 @@ namespace YooAsset.Editor
// 收集打包资源
foreach (var collector in Collectors)
{
var temper = collector.GetAllCollectAssets(buildMode, enableAddressable, this);
var temper = collector.GetAllCollectAssets(command, this);
foreach (var assetInfo in temper)
{
if (result.ContainsKey(assetInfo.AssetPath) == false)
@ -94,7 +94,7 @@ namespace YooAsset.Editor
}
// 检测可寻址地址是否重复
if (enableAddressable)
if (command.EnableAddressable)
{
HashSet<string> adressTemper = new HashSet<string>();
foreach (var collectInfoPair in result)

View File

@ -56,14 +56,14 @@ namespace YooAsset.Editor
/// <summary>
/// 获取打包收集的资源文件
/// </summary>
public List<CollectAssetInfo> GetAllCollectAssets(EBuildMode buildMode, bool enableAddressable)
public List<CollectAssetInfo> GetAllCollectAssets(CollectCommand command)
{
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000);
// 收集打包资源
foreach (var group in Groups)
{
var temper = group.GetAllCollectAssets(buildMode, enableAddressable);
var temper = group.GetAllCollectAssets(command);
foreach (var assetInfo in temper)
{
if (result.ContainsKey(assetInfo.AssetPath) == false)
@ -74,7 +74,7 @@ namespace YooAsset.Editor
}
// 检测可寻址地址是否重复
if (enableAddressable)
if (command.EnableAddressable)
{
HashSet<string> adressTemper = new HashSet<string>();
foreach (var collectInfoPair in result)

View File

@ -9,7 +9,7 @@ namespace YooAsset.Editor
public class AssetBundleCollectorSetting : ScriptableObject
{
/// <summary>
/// 是否显示包裹视图
/// 是否显示包裹列表视图
/// </summary>
public bool ShowPackageView = false;
@ -18,6 +18,11 @@ namespace YooAsset.Editor
/// </summary>
public bool EnableAddressable = false;
/// <summary>
/// 资源包名唯一化
/// </summary>
public bool UniqueBundleName = false;
/// <summary>
/// 包裹列表
/// </summary>
@ -76,37 +81,43 @@ namespace YooAsset.Editor
Debug.LogWarning($"Not found package : {packageName}");
return new List<string>();
}
/// <summary>
/// 获取包裹收集的资源文件
/// </summary>
public List<CollectAssetInfo> GetPackageAssets(EBuildMode buildMode, string packageName)
public CollectResult GetPackageAssets(EBuildMode buildMode, string packageName)
{
if (string.IsNullOrEmpty(packageName))
throw new Exception("Build Package name is null or mepty !");
throw new Exception("Build package name is null or mepty !");
foreach (var package in Packages)
{
if (package.PackageName == packageName)
{
return package.GetAllCollectAssets(buildMode, EnableAddressable);
CollectCommand command = new CollectCommand(buildMode, EnableAddressable);
CollectResult collectResult = new CollectResult(package.PackageName, EnableAddressable, UniqueBundleName);
collectResult.SetCollectAssets(package.GetAllCollectAssets(command));
return collectResult;
}
}
throw new Exception($"Not found collector pacakge : {packageName}");
}
/// <summary>
/// 获取所有包裹收集的资源文件
/// </summary>
public List<CollectAssetInfo> GetAllPackageAssets(EBuildMode buildMode)
public List<CollectResult> GetAllPackageAssets(EBuildMode buildMode)
{
List<CollectAssetInfo> result = new List<CollectAssetInfo>(1000);
List<CollectResult> collectResultList = new List<CollectResult>(1000);
foreach (var package in Packages)
{
var temper = package.GetAllCollectAssets(buildMode, EnableAddressable);
result.AddRange(temper);
CollectCommand command = new CollectCommand(buildMode, EnableAddressable);
CollectResult collectResult = new CollectResult(package.PackageName, EnableAddressable, UniqueBundleName);
collectResult.SetCollectAssets(package.GetAllCollectAssets(command));
collectResultList.Add(collectResult);
}
return result;
return collectResultList;
}
}
}

View File

@ -347,6 +347,11 @@ namespace YooAsset.Editor
Setting.EnableAddressable = enableAddressable;
IsDirty = true;
}
public static void ModifyUniqueBundleName(bool uniqueBundleName)
{
Setting.UniqueBundleName = uniqueBundleName;
IsDirty = true;
}
// 资源包裹编辑相关
public static void CreatePackage(string packageName)

View File

@ -27,6 +27,7 @@ namespace YooAsset.Editor
private Toggle _showPackageToogle;
private Toggle _enableAddressableToogle;
private Toggle _uniqueBundleNameToogle;
private VisualElement _packageContainer;
private ListView _packageListView;
@ -87,6 +88,12 @@ namespace YooAsset.Editor
AssetBundleCollectorSettingData.ModifyAddressable(evt.newValue);
RefreshWindow();
});
_uniqueBundleNameToogle = root.Q<Toggle>("UniqueBundleName");
_uniqueBundleNameToogle.RegisterValueChangedCallback(evt =>
{
AssetBundleCollectorSettingData.ModifyUniqueBundleName(evt.newValue);
RefreshWindow();
});
// 配置修复按钮
var fixBtn = root.Q<Button>("FixButton");
@ -733,8 +740,8 @@ namespace YooAsset.Editor
try
{
bool enableAdressable = AssetBundleCollectorSettingData.Setting.EnableAddressable;
collectAssetInfos = collector.GetAllCollectAssets(EBuildMode.DryRunBuild, enableAdressable, group);
CollectCommand command = new CollectCommand(EBuildMode.DryRunBuild, _enableAddressableToogle.value);
collectAssetInfos = collector.GetAllCollectAssets(command, group);
}
catch (System.Exception e)
{

View File

@ -8,6 +8,7 @@
<ui:VisualElement name="PublicContainer" style="height: 30px; background-color: rgb(67, 67, 67); flex-direction: row; border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px;">
<ui:Toggle label="Show Packages" name="ShowPackages" style="width: 196px; -unity-text-align: middle-left;" />
<ui:Toggle label="Enable Addressable" name="EnableAddressable" style="width: 196px; -unity-text-align: middle-left;" />
<ui:Toggle label="Unique Bundle Name" name="UniqueBundleName" style="width: 196px; -unity-text-align: middle-left;" />
</ui:VisualElement>
<ui:VisualElement name="ContentContainer" style="flex-grow: 1; flex-direction: row;">
<ui:VisualElement name="PackageContainer" style="width: 200px; flex-grow: 0; background-color: rgb(67, 67, 67); border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px;">

View File

@ -50,5 +50,13 @@ namespace YooAsset.Editor
AssetTags = assetTags;
IsRawAsset = isRawAsset;
}
/// <summary>
/// 资源包名称追加包裹名
/// </summary>
public void BundleNameAppendPackageName(string packageName)
{
BundleName = $"{packageName.ToLower()}_{BundleName}";
}
}
}

View File

@ -0,0 +1,22 @@

namespace YooAsset.Editor
{
public class CollectCommand
{
/// <summary>
/// 构建模式
/// </summary>
public EBuildMode BuildMode { private set; get; }
/// <summary>
/// 是否启用可寻址资源定位
/// </summary>
public bool EnableAddressable { private set; get; }
public CollectCommand(EBuildMode buildMode, bool enableAddressable)
{
BuildMode = buildMode;
EnableAddressable = enableAddressable;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b1741e85d76b28d41a4da3cd0e3e6f20
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,49 @@
using System.Collections;
using System.Collections.Generic;
namespace YooAsset.Editor
{
public class CollectResult
{
/// <summary>
/// 包裹名称
/// </summary>
public string PackageName { private set; get; }
/// <summary>
/// 是否启用可寻址资源定位
/// </summary>
public bool EnableAddressable { private set; get; }
/// <summary>
/// 资源包名唯一化
/// </summary>
public bool UniqueBundleName { private set; get; }
/// <summary>
/// 收集的资源信息列表
/// </summary>
public List<CollectAssetInfo> CollectAssets { private set; get; }
public CollectResult(string packageName, bool enableAddressable, bool uniqueBundleName)
{
PackageName = packageName;
EnableAddressable = enableAddressable;
UniqueBundleName = uniqueBundleName;
}
public void SetCollectAssets(List<CollectAssetInfo> collectAssets)
{
CollectAssets = collectAssets;
if (UniqueBundleName)
{
foreach (var collectAsset in CollectAssets)
{
collectAsset.BundleNameAppendPackageName(PackageName);
}
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: dbbd465f929ee33408441b62d19c7d10
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: