Optimize packaging bundle core logic

优化了打包的核心逻辑,支持设置依赖资源收集器。
This commit is contained in:
hevinci
2022-04-30 23:14:20 +08:00
parent b443a1c308
commit 650d8689ee
22 changed files with 162 additions and 85 deletions
@@ -17,7 +17,7 @@ namespace YooAsset.Editor
/// <summary>
/// 收集器类型
/// </summary>
public ECollectorType CollectorType = ECollectorType.MainCollector;
public ECollectorType CollectorType = ECollectorType.MainAssetCollector;
/// <summary>
/// 寻址规则类名
@@ -47,12 +47,19 @@ namespace YooAsset.Editor
{
if (AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(CollectPath) == null)
return false;
if (AssetBundleGrouperSettingData.HasPackRuleName(PackRuleName) == false)
return false;
if (AssetBundleGrouperSettingData.HasFilterRuleName(FilterRuleName) == false)
if (CollectorType == ECollectorType.None)
return false;
if (AssetBundleGrouperSettingData.HasAddressRuleName(AddressRuleName) == false)
return false;
if (AssetBundleGrouperSettingData.HasPackRuleName(PackRuleName) == false)
return false;
if (AssetBundleGrouperSettingData.HasFilterRuleName(FilterRuleName) == false)
return false;
return true;
}
@@ -86,8 +93,8 @@ namespace YooAsset.Editor
bool isRawAsset = PackRuleName == nameof(PackRawFile);
// 检测原生资源包的收集器类型
if (isRawAsset && CollectorType != ECollectorType.MainCollector)
throw new Exception($"The raw file must be set to {nameof(ECollectorType)}.{ECollectorType.MainCollector} : {CollectPath}");
if (isRawAsset && CollectorType != ECollectorType.MainAssetCollector)
throw new Exception($"The raw file must be set to {nameof(ECollectorType)}.{ECollectorType.MainAssetCollector} : {CollectPath}");
// 收集打包资源
if (AssetDatabase.IsValidFolder(CollectPath))
@@ -130,7 +137,7 @@ namespace YooAsset.Editor
HashSet<string> adressTemper = new HashSet<string>();
foreach (var collectInfoPair in result)
{
if (collectInfoPair.Value.CollectorType == ECollectorType.MainCollector)
if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector)
{
string address = collectInfoPair.Value.Address;
if (adressTemper.Contains(address) == false)
@@ -189,7 +196,7 @@ namespace YooAsset.Editor
}
private string GetAddress(AssetBundleGrouper grouper, string assetPath)
{
if (CollectorType != ECollectorType.MainCollector)
if (CollectorType != ECollectorType.MainAssetCollector)
return string.Empty;
IAddressRule addressRuleInstance = AssetBundleGrouperSettingData.GetAddressRuleInstance(AddressRuleName);
@@ -68,7 +68,7 @@ namespace YooAsset.Editor
HashSet<string> adressTemper = new HashSet<string>();
foreach (var collectInfoPair in result)
{
if (collectInfoPair.Value.CollectorType == ECollectorType.MainCollector)
if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector)
{
string address = collectInfoPair.Value.Address;
if (adressTemper.Contains(address) == false)
@@ -22,14 +22,14 @@ namespace YooAsset.Editor
var collectAssetList = AssetBundleGrouperSettingData.Setting.GetAllCollectAssets();
foreach (var collectAsset in collectAssetList)
{
if(collectAsset.CollectorType != ECollectorType.MainCollector)
continue;
string address = collectAsset.Address;
if (_locationDic.ContainsKey(address))
UnityEngine.Debug.LogWarning($"Address have existed : {address}");
else
_locationDic.Add(address, collectAsset);
if(collectAsset.CollectorType == ECollectorType.MainAssetCollector)
{
string address = collectAsset.Address;
if (_locationDic.ContainsKey(address))
throw new Exception($"The address is existed : {address} in grouper setting.");
else
_locationDic.Add(address, collectAsset);
}
}
}
else
@@ -37,24 +37,25 @@ namespace YooAsset.Editor
var collectAssetList = AssetBundleGrouperSettingData.Setting.GetAllCollectAssets();
foreach (var collectAsset in collectAssetList)
{
if (collectAsset.CollectorType != ECollectorType.MainCollector)
continue;
// 添加原始路径
string assetPath = collectAsset.AssetPath;
if (_locationDic.ContainsKey(assetPath))
UnityEngine.Debug.LogWarning($"Asset path have existed : {assetPath}");
else
_locationDic.Add(assetPath, collectAsset);
// 添加去掉后缀名的路径
if (Path.HasExtension(assetPath))
if (collectAsset.CollectorType == ECollectorType.MainAssetCollector)
{
string assetPathWithoutExtension = StringUtility.RemoveExtension(assetPath);
if (_locationDic.ContainsKey(assetPathWithoutExtension))
UnityEngine.Debug.LogWarning($"Asset path have existed : {assetPathWithoutExtension}");
// 添加原始路径
// 注意:我们不允许原始路径存在重名
string assetPath = collectAsset.AssetPath;
if (_locationDic.ContainsKey(assetPath))
throw new Exception($"Asset path have existed : {assetPath}");
else
_locationDic.Add(assetPathWithoutExtension, collectAsset);
_locationDic.Add(assetPath, collectAsset);
// 添加去掉后缀名的路径
if (Path.HasExtension(assetPath))
{
string assetPathWithoutExtension = StringUtility.RemoveExtension(assetPath);
if (_locationDic.ContainsKey(assetPathWithoutExtension))
UnityEngine.Debug.LogWarning($"Asset path have existed : {assetPathWithoutExtension}");
else
_locationDic.Add(assetPathWithoutExtension, collectAsset);
}
}
}
}
@@ -66,7 +66,7 @@ namespace YooAsset.Editor
HashSet<string> adressTemper = new HashSet<string>();
foreach (var collectInfoPair in result)
{
if (collectInfoPair.Value.CollectorType == ECollectorType.MainCollector)
if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector)
{
string address = collectInfoPair.Value.Address;
if (adressTemper.Contains(address) == false)
@@ -39,7 +39,12 @@ namespace YooAsset.Editor
VisualElement root = this.rootVisualElement;
_collectorTypeList = new List<string>() { $"{nameof(ECollectorType.MainCollector)}", $"{nameof(ECollectorType.StaticCollector)}"};
_collectorTypeList = new List<string>()
{
$"{nameof(ECollectorType.MainAssetCollector)}",
$"{nameof(ECollectorType.StaticAssetCollector)}",
$"{nameof(ECollectorType.DependAssetCollector)}"
};
_addressRuleList = AssetBundleGrouperSettingData.GetAddressRuleNames();
_packRuleList = AssetBundleGrouperSettingData.GetPackRuleNames();
_filterRuleList = AssetBundleGrouperSettingData.GetFilterRuleNames();
@@ -371,7 +376,7 @@ namespace YooAsset.Editor
var foldout = new Foldout();
foldout.name = "Foldout1";
foldout.value = false;
foldout.text = "Assets";
foldout.text = "Main Assets";
elementFoldout.Add(foldout);
}
@@ -474,7 +479,13 @@ namespace YooAsset.Editor
// 清空旧元素
foldout.Clear();
if (collector.IsValid() && collector.CollectorType == ECollectorType.MainCollector)
if (collector.IsValid() == false)
{
Debug.LogWarning($"The collector is invalid : {collector.CollectPath} in grouper : {grouper.GrouperName}");
return;
}
if (collector.CollectorType == ECollectorType.MainAssetCollector || collector.CollectorType == ECollectorType.StaticAssetCollector)
{
List<CollectAssetInfo> collectAssetInfos = null;
@@ -6,14 +6,20 @@ namespace YooAsset.Editor
public enum ECollectorType
{
/// <summary>
/// 收集参与打包构建的资源对象,并全部写入到资源清单的资源列表里(可以通过代码加载)。
/// 收集参与打包的主资源对象,并写入到资源清单的资源列表里(可以通过代码加载)。
/// </summary>
MainCollector,
MainAssetCollector,
/// <summary>
/// 收集参与打包构建的资源对象,但不写入到资源清单的资源列表里(无法通过代码加载)。
/// 收集参与打包的主资源对象,但不写入到资源清单的资源列表里(无法通过代码加载)。
/// </summary>
StaticCollector,
StaticAssetCollector,
/// <summary>
/// 收集参与打包的依赖资源对象,但不写入到资源清单的资源列表里(无法通过代码加载)。
/// 注意:如果依赖资源对象没有被主资源对象引用,则不参与打包构建。
/// </summary>
DependAssetCollector,
/// <summary>
/// 该收集器类型不能被设置