update editor code

1. 移除了BuildParameters.AutoAnalyzeRedundancy字段
2. 移除了DefaultShareAssetPackRule
3. 新增了ZeroRedundancySharedPackRule
4. 新增了FullRedundancySharedPackRule
pull/122/head
hevinci 2023-06-27 14:18:54 +08:00
parent 84f9d1985e
commit f54c8d6da4
11 changed files with 62 additions and 66 deletions

View File

@ -275,8 +275,7 @@ namespace YooAsset.Editor
buildParameters.PackageName = AssetBundleBuilderSettingData.Setting.BuildPackage;
buildParameters.PackageVersion = _buildVersionField.value;
buildParameters.VerifyBuildingResult = true;
buildParameters.AutoAnalyzeRedundancy = true;
buildParameters.SharedPackRule = new DefaultSharedPackRule();
buildParameters.SharedPackRule = new ZeroRedundancySharedPackRule();
buildParameters.EncryptionServices = CreateEncryptionServicesInstance();
buildParameters.CompressOption = AssetBundleBuilderSettingData.Setting.CompressOption;
buildParameters.OutputNameStyle = AssetBundleBuilderSettingData.Setting.OutputNameStyle;

View File

@ -164,7 +164,7 @@ namespace YooAsset.Editor
/// <summary>
/// 计算共享资源包的完整包名
/// </summary>
public void CalculateShareBundleName(ISharedPackRule packRule, bool uniqueBundleName, string packageName, string shadersBundleName)
public void CalculateShareBundleName(ISharedPackRule sharedPackRule, bool uniqueBundleName, string packageName, string shadersBundleName)
{
if (CollectorType != ECollectorType.None)
return;
@ -180,7 +180,7 @@ namespace YooAsset.Editor
{
if (_referenceBundleNames.Count > 1)
{
PackRuleResult packRuleResult = packRule.GetPackRuleResult(AssetPath);
PackRuleResult packRuleResult = sharedPackRule.GetPackRuleResult(AssetPath);
BundleName = packRuleResult.GetShareBundleName(packageName, uniqueBundleName);
}
else
@ -196,12 +196,9 @@ namespace YooAsset.Editor
/// </summary>
public bool IsRedundancyAsset()
{
if (CollectorType != ECollectorType.None)
if (HasBundleName())
return false;
if (IsRawAsset)
throw new Exception("Should never get here !");
return _referenceBundleNames.Count > 1;
}

View File

@ -49,7 +49,7 @@ namespace YooAsset.Editor
/// <summary>
/// 参与构建的资源列表
/// 注意:不包含零依赖资源
/// 注意:不包含零依赖资源和冗余资源
/// </summary>
public readonly List<BuildAssetInfo> AllMainAssets = new List<BuildAssetInfo>();
@ -149,7 +149,15 @@ namespace YooAsset.Editor
}
/// <summary>
/// 获取该资源包内的所有资源(包括零依赖资源)
/// 获取构建的资源路径列表
/// </summary>
public string[] GetAllMainAssetPaths()
{
return AllMainAssets.Select(t => t.AssetPath).ToArray();
}
/// <summary>
/// 获取该资源包内的所有资源(包括零依赖资源和冗余资源)
/// </summary>
public List<string> GetAllBuiltinAssetPaths()
{
@ -161,6 +169,7 @@ namespace YooAsset.Editor
continue;
foreach (var dependAssetInfo in assetInfo.AllDependAssetInfos)
{
// 注意:依赖资源里只添加零依赖资源和冗余资源
if (dependAssetInfo.HasBundleName() == false)
{
if (result.Contains(dependAssetInfo.AssetPath) == false)
@ -171,22 +180,6 @@ namespace YooAsset.Editor
return result;
}
/// <summary>
/// 获取构建的资源路径列表
/// </summary>
public string[] GetAllMainAssetPaths()
{
return AllMainAssets.Select(t => t.AssetPath).ToArray();
}
/// <summary>
/// 获取所有写入补丁清单的资源
/// </summary>
public BuildAssetInfo[] GetAllMainAssetInfos()
{
return AllMainAssets.Where(t => t.CollectorType == ECollectorType.MainAssetCollector).ToArray();
}
/// <summary>
/// 创建AssetBundleBuild类
/// </summary>
@ -200,6 +193,14 @@ namespace YooAsset.Editor
return build;
}
/// <summary>
/// 获取所有写入补丁清单的资源
/// </summary>
public BuildAssetInfo[] GetAllManifestAssetInfos()
{
return AllMainAssets.Where(t => t.CollectorType == ECollectorType.MainAssetCollector).ToArray();
}
/// <summary>
/// 创建PackageBundle类
/// </summary>

View File

@ -77,11 +77,6 @@ namespace YooAsset.Editor
/// </summary>
public bool VerifyBuildingResult = false;
/// <summary>
/// 自动分析冗余资源
/// </summary>
public bool AutoAnalyzeRedundancy = true;
/// <summary>
/// 共享资源的打包规则
/// </summary>

View File

@ -73,11 +73,6 @@ namespace YooAsset.Editor
/// </summary>
public bool UniqueBundleName;
/// <summary>
/// 自动分析冗余
/// </summary>
public bool AutoAnalyzeRedundancy;
/// <summary>
/// 共享资源的打包规则类名
/// </summary>

View File

@ -139,7 +139,7 @@ namespace YooAsset.Editor
List<PackageAsset> result = new List<PackageAsset>(1000);
foreach (var bundleInfo in buildMapContext.Collection)
{
var assetInfos = bundleInfo.GetAllMainAssetInfos();
var assetInfos = bundleInfo.GetAllManifestAssetInfos();
foreach (var assetInfo in assetInfos)
{
PackageAsset packageAsset = new PackageAsset();

View File

@ -49,7 +49,6 @@ namespace YooAsset.Editor
buildReport.Summary.LocationToLower = buildMapContext.Command.LocationToLower;
buildReport.Summary.IncludeAssetGUID = buildMapContext.Command.IncludeAssetGUID;
buildReport.Summary.UniqueBundleName = buildMapContext.Command.UniqueBundleName;
buildReport.Summary.AutoAnalyzeRedundancy = buildParameters.AutoAnalyzeRedundancy;
buildReport.Summary.SharedPackRuleClassName = buildParameters.SharedPackRule == null ?
"null" : buildParameters.SharedPackRule.GetType().FullName;
buildReport.Summary.EncryptionServicesClassName = buildParameters.EncryptionServices == null ?
@ -161,7 +160,7 @@ namespace YooAsset.Editor
}
/// <summary>
/// 获取该资源包内的所有资源(包括零依赖资源)
/// 获取该资源包内的所有资源
/// </summary>
private List<string> GetAllBuiltinAssets(BuildMapContext buildMapContext, string bundleName)
{

View File

@ -29,7 +29,6 @@ namespace YooAsset.Editor
var buildMode = buildParameters.BuildMode;
var packageName = buildParameters.PackageName;
var sharedPackRule = buildParameters.SharedPackRule;
var autoAnalyzeRedundancy = buildParameters.AutoAnalyzeRedundancy;
Dictionary<string, BuildAssetInfo> allBuildAssetInfoDic = new Dictionary<string, BuildAssetInfo>(1000);
@ -100,34 +99,29 @@ namespace YooAsset.Editor
context.AssetFileCount = allBuildAssetInfoDic.Count;
context.Command = collectResult.Command;
// 8. 计算共享的资源包名
if (autoAnalyzeRedundancy)
// 8. 计算共享资源的包名
var command = collectResult.Command;
foreach (var buildAssetInfo in allBuildAssetInfoDic.Values)
{
var command = collectResult.Command;
foreach (var buildAssetInfo in allBuildAssetInfoDic.Values)
{
buildAssetInfo.CalculateShareBundleName(sharedPackRule, command.UniqueBundleName, command.PackageName, command.ShadersBundleName);
}
buildAssetInfo.CalculateShareBundleName(sharedPackRule, command.UniqueBundleName, command.PackageName, command.ShadersBundleName);
}
else
// 9. 记录冗余资源
foreach (var buildAssetInfo in allBuildAssetInfoDic.Values)
{
// 记录冗余资源
foreach (var buildAssetInfo in allBuildAssetInfoDic.Values)
if (buildAssetInfo.IsRedundancyAsset())
{
if (buildAssetInfo.IsRedundancyAsset())
{
var redundancyInfo = new ReportRedundancyInfo();
redundancyInfo.AssetPath = buildAssetInfo.AssetPath;
redundancyInfo.AssetType = AssetDatabase.GetMainAssetTypeAtPath(buildAssetInfo.AssetPath).Name;
redundancyInfo.AssetGUID = AssetDatabase.AssetPathToGUID(buildAssetInfo.AssetPath);
redundancyInfo.FileSize = FileUtility.GetFileSize(buildAssetInfo.AssetPath);
redundancyInfo.Number = buildAssetInfo.GetReferenceBundleCount();
context.RedundancyInfos.Add(redundancyInfo);
}
var redundancyInfo = new ReportRedundancyInfo();
redundancyInfo.AssetPath = buildAssetInfo.AssetPath;
redundancyInfo.AssetType = AssetDatabase.GetMainAssetTypeAtPath(buildAssetInfo.AssetPath).Name;
redundancyInfo.AssetGUID = AssetDatabase.AssetPathToGUID(buildAssetInfo.AssetPath);
redundancyInfo.FileSize = FileUtility.GetFileSize(buildAssetInfo.AssetPath);
redundancyInfo.Number = buildAssetInfo.GetReferenceBundleCount();
context.RedundancyInfos.Add(redundancyInfo);
}
}
// 9. 移除不参与构建的资源
// 10. 移除不参与构建的资源
List<BuildAssetInfo> removeBuildList = new List<BuildAssetInfo>();
foreach (var buildAssetInfo in allBuildAssetInfoDic.Values)
{
@ -139,7 +133,7 @@ namespace YooAsset.Editor
allBuildAssetInfoDic.Remove(removeValue.AssetPath);
}
// 10. 构建资源包
// 11. 构建资源列表
var allPackAssets = allBuildAssetInfoDic.Values.ToList();
if (allPackAssets.Count == 0)
throw new Exception("构建的资源列表不能为空");
@ -147,6 +141,7 @@ namespace YooAsset.Editor
{
context.PackAsset(assetInfo);
}
return context;
}
private void RemoveZeroReferenceAssets(List<CollectAssetInfo> allCollectAssetInfos)

View File

@ -54,6 +54,10 @@ namespace YooAsset.Editor
/// </summary>
public string GetShareBundleName(string packageName, bool uniqueBundleName)
{
// 注意:冗余的共享资源包名返回空
if (string.IsNullOrEmpty(_bundleName) && string.IsNullOrEmpty(_bundleExtension))
return string.Empty;
string fullName;
string bundleName = EditorTools.GetRegularPath(_bundleName).Replace('/', '_').Replace('.', '_').ToLower();
if (uniqueBundleName)

View File

@ -5,9 +5,9 @@ using UnityEditor;
namespace YooAsset.Editor
{
/// <summary>
/// 零冗余共享资源打包规则
/// 零冗余共享资源打包规则
/// </summary>
public class DefaultSharedPackRule : ISharedPackRule
public class ZeroRedundancySharedPackRule : ISharedPackRule
{
public PackRuleResult GetPackRuleResult(string assetPath)
{
@ -16,4 +16,16 @@ namespace YooAsset.Editor
return result;
}
}
/// <summary>
/// 全部冗余的共享资源打包规则
/// </summary>
public class FullRedundancySharedPackRule : ISharedPackRule
{
public PackRuleResult GetPackRuleResult(string assetPath)
{
PackRuleResult result = new PackRuleResult(string.Empty, string.Empty);
return result;
}
}
}

View File

@ -71,7 +71,6 @@ namespace YooAsset.Editor
_items.Add(new ItemWrapper("资源定位地址大小写不敏感", $"{buildReport.Summary.LocationToLower}"));
_items.Add(new ItemWrapper("包含资源GUID数据", $"{buildReport.Summary.IncludeAssetGUID}"));
_items.Add(new ItemWrapper("资源包名唯一化", $"{buildReport.Summary.UniqueBundleName}"));
_items.Add(new ItemWrapper("自动分析冗余资源", $"{buildReport.Summary.AutoAnalyzeRedundancy}"));
_items.Add(new ItemWrapper("共享资源打包规则", buildReport.Summary.SharedPackRuleClassName));
_items.Add(new ItemWrapper("资源加密服务类", buildReport.Summary.EncryptionServicesClassName));