Update AssetBundleCollector

AssetBundleGrouper变更为AssetBundleCollector
pull/9/head
hevinci 2022-05-04 21:24:51 +08:00
parent d592fb96a6
commit eafdb8cd31
40 changed files with 247 additions and 247 deletions

View File

@ -176,7 +176,7 @@ namespace YooAsset.Editor
buildParameters.BuildVersion = _buildVersionField.value; buildParameters.BuildVersion = _buildVersionField.value;
buildParameters.BuildinTags = _buildTagsField.value; buildParameters.BuildinTags = _buildTagsField.value;
buildParameters.VerifyBuildingResult = true; buildParameters.VerifyBuildingResult = true;
buildParameters.EnableAddressable = AssetBundleGrouperSettingData.Setting.EnableAddressable; buildParameters.EnableAddressable = AssetBundleCollectorSettingData.Setting.EnableAddressable;
buildParameters.AppendFileExtension = _appendExtensionToggle.value; buildParameters.AppendFileExtension = _appendExtensionToggle.value;
buildParameters.EncryptionServices = CreateEncryptionServicesInstance(); buildParameters.EncryptionServices = CreateEncryptionServicesInstance();
buildParameters.CompressOption = (ECompressOption)_compressionField.value; buildParameters.CompressOption = (ECompressOption)_compressionField.value;

View File

@ -19,7 +19,7 @@ namespace YooAsset.Editor
buildParameters.BuildMode = EBuildMode.FastRunBuild; buildParameters.BuildMode = EBuildMode.FastRunBuild;
buildParameters.BuildVersion = AssetBundleBuilderSettingData.Setting.BuildVersion; buildParameters.BuildVersion = AssetBundleBuilderSettingData.Setting.BuildVersion;
buildParameters.BuildinTags = AssetBundleBuilderSettingData.Setting.BuildTags; buildParameters.BuildinTags = AssetBundleBuilderSettingData.Setting.BuildTags;
buildParameters.EnableAddressable = AssetBundleGrouperSettingData.Setting.EnableAddressable; buildParameters.EnableAddressable = AssetBundleCollectorSettingData.Setting.EnableAddressable;
AssetBundleBuilder builder = new AssetBundleBuilder(); AssetBundleBuilder builder = new AssetBundleBuilder();
bool buildResult = builder.Run(buildParameters); bool buildResult = builder.Run(buildParameters);

View File

@ -147,11 +147,11 @@ namespace YooAsset.Editor
if (IsRawAsset) if (IsRawAsset)
throw new Exception("Should never get here !"); throw new Exception("Should never get here !");
if (AssetBundleGrouperSettingData.Setting.AutoCollectShaders) if (AssetBundleCollectorSettingData.Setting.AutoCollectShaders)
{ {
if (IsShaderAsset) if (IsShaderAsset)
{ {
string shareBundleName = $"{AssetBundleGrouperSettingData.Setting.ShadersBundleName}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}"; string shareBundleName = $"{AssetBundleCollectorSettingData.Setting.ShadersBundleName}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}";
_shareBundleName = EditorTools.GetRegularPath(shareBundleName).ToLower(); _shareBundleName = EditorTools.GetRegularPath(shareBundleName).ToLower();
return; return;
} }

View File

@ -16,10 +16,10 @@ namespace YooAsset.Editor
Dictionary<string, BuildAssetInfo> buildAssetDic = new Dictionary<string, BuildAssetInfo>(1000); Dictionary<string, BuildAssetInfo> buildAssetDic = new Dictionary<string, BuildAssetInfo>(1000);
// 1. 检测配置合法性 // 1. 检测配置合法性
AssetBundleGrouperSettingData.Setting.CheckConfigError(); AssetBundleCollectorSettingData.Setting.CheckConfigError();
// 2. 获取所有主动收集的资源 // 2. 获取所有主动收集的资源
List<CollectAssetInfo> allCollectAssets = AssetBundleGrouperSettingData.Setting.GetAllCollectAssets(); List<CollectAssetInfo> allCollectAssets = AssetBundleCollectorSettingData.Setting.GetAllCollectAssets();
// 3. 剔除未被引用的依赖资源 // 3. 剔除未被引用的依赖资源
List<CollectAssetInfo> removeDependList = new List<CollectAssetInfo>(); List<CollectAssetInfo> removeDependList = new List<CollectAssetInfo>();

View File

@ -33,8 +33,8 @@ namespace YooAsset.Editor
buildReport.Summary.EnableAddressable = buildParameters.Parameters.EnableAddressable; buildReport.Summary.EnableAddressable = buildParameters.Parameters.EnableAddressable;
buildReport.Summary.EnableAutoCollect = buildParameters.Parameters.EnableAutoCollect; buildReport.Summary.EnableAutoCollect = buildParameters.Parameters.EnableAutoCollect;
buildReport.Summary.AppendFileExtension = buildParameters.Parameters.AppendFileExtension; buildReport.Summary.AppendFileExtension = buildParameters.Parameters.AppendFileExtension;
buildReport.Summary.AutoCollectShaders = AssetBundleGrouperSettingData.Setting.AutoCollectShaders; buildReport.Summary.AutoCollectShaders = AssetBundleCollectorSettingData.Setting.AutoCollectShaders;
buildReport.Summary.ShadersBundleName = AssetBundleGrouperSettingData.Setting.ShadersBundleName; buildReport.Summary.ShadersBundleName = AssetBundleCollectorSettingData.Setting.ShadersBundleName;
buildReport.Summary.EncryptionServicesClassName = buildParameters.Parameters.EncryptionServices == null ? buildReport.Summary.EncryptionServicesClassName = buildParameters.Parameters.EncryptionServices == null ?
"null" : buildParameters.Parameters.EncryptionServices.GetType().FullName; "null" : buildParameters.Parameters.EncryptionServices.GetType().FullName;

View File

@ -51,13 +51,13 @@ namespace YooAsset.Editor
if (CollectorType == ECollectorType.None) if (CollectorType == ECollectorType.None)
return false; return false;
if (AssetBundleGrouperSettingData.HasAddressRuleName(AddressRuleName) == false) if (AssetBundleCollectorSettingData.HasAddressRuleName(AddressRuleName) == false)
return false; return false;
if (AssetBundleGrouperSettingData.HasPackRuleName(PackRuleName) == false) if (AssetBundleCollectorSettingData.HasPackRuleName(PackRuleName) == false)
return false; return false;
if (AssetBundleGrouperSettingData.HasFilterRuleName(FilterRuleName) == false) if (AssetBundleCollectorSettingData.HasFilterRuleName(FilterRuleName) == false)
return false; return false;
return true; return true;
@ -74,20 +74,20 @@ namespace YooAsset.Editor
if (CollectorType == ECollectorType.None) if (CollectorType == ECollectorType.None)
throw new Exception($"{nameof(ECollectorType)}.{ECollectorType.None} is invalid in collector : {CollectPath}"); throw new Exception($"{nameof(ECollectorType)}.{ECollectorType.None} is invalid in collector : {CollectPath}");
if (AssetBundleGrouperSettingData.HasPackRuleName(PackRuleName) == false) if (AssetBundleCollectorSettingData.HasPackRuleName(PackRuleName) == false)
throw new Exception($"Invalid {nameof(IPackRule)} class type : {PackRuleName} in collector : {CollectPath}"); throw new Exception($"Invalid {nameof(IPackRule)} class type : {PackRuleName} in collector : {CollectPath}");
if (AssetBundleGrouperSettingData.HasFilterRuleName(FilterRuleName) == false) if (AssetBundleCollectorSettingData.HasFilterRuleName(FilterRuleName) == false)
throw new Exception($"Invalid {nameof(IFilterRule)} class type : {FilterRuleName} in collector : {CollectPath}"); throw new Exception($"Invalid {nameof(IFilterRule)} class type : {FilterRuleName} in collector : {CollectPath}");
if (AssetBundleGrouperSettingData.HasAddressRuleName(AddressRuleName) == false) if (AssetBundleCollectorSettingData.HasAddressRuleName(AddressRuleName) == false)
throw new Exception($"Invalid {nameof(IAddressRule)} class type : {AddressRuleName} in collector : {CollectPath}"); throw new Exception($"Invalid {nameof(IAddressRule)} class type : {AddressRuleName} in collector : {CollectPath}");
} }
/// <summary> /// <summary>
/// 获取打包收集的资源文件 /// 获取打包收集的资源文件
/// </summary> /// </summary>
public List<CollectAssetInfo> GetAllCollectAssets(AssetBundleGrouper grouper) public List<CollectAssetInfo> GetAllCollectAssets(AssetBundleCollectorGroup group)
{ {
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(1000); Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(1000);
bool isRawAsset = PackRuleName == nameof(PackRawFile); bool isRawAsset = PackRuleName == nameof(PackRawFile);
@ -97,7 +97,7 @@ namespace YooAsset.Editor
throw new Exception($"The raw file must be set to {nameof(ECollectorType)}.{ECollectorType.MainAssetCollector} : {CollectPath}"); throw new Exception($"The raw file must be set to {nameof(ECollectorType)}.{ECollectorType.MainAssetCollector} : {CollectPath}");
if (string.IsNullOrEmpty(CollectPath)) if (string.IsNullOrEmpty(CollectPath))
throw new Exception($"The collect path is null or empty in grouper : {grouper.GrouperName}"); throw new Exception($"The collect path is null or empty in group : {group.GroupName}");
// 收集打包资源 // 收集打包资源
if (AssetDatabase.IsValidFolder(CollectPath)) if (AssetDatabase.IsValidFolder(CollectPath))
@ -110,7 +110,7 @@ namespace YooAsset.Editor
{ {
if (result.ContainsKey(assetPath) == false) if (result.ContainsKey(assetPath) == false)
{ {
var collectAssetInfo = CreateCollectAssetInfo(grouper, assetPath, isRawAsset); var collectAssetInfo = CreateCollectAssetInfo(group, assetPath, isRawAsset);
result.Add(assetPath, collectAssetInfo); result.Add(assetPath, collectAssetInfo);
} }
else else
@ -125,7 +125,7 @@ namespace YooAsset.Editor
string assetPath = CollectPath; string assetPath = CollectPath;
if (IsValidateAsset(assetPath) && IsCollectAsset(assetPath)) if (IsValidateAsset(assetPath) && IsCollectAsset(assetPath))
{ {
var collectAssetInfo = CreateCollectAssetInfo(grouper, assetPath, isRawAsset); var collectAssetInfo = CreateCollectAssetInfo(group, assetPath, isRawAsset);
result.Add(assetPath, collectAssetInfo); result.Add(assetPath, collectAssetInfo);
} }
else else
@ -135,7 +135,7 @@ namespace YooAsset.Editor
} }
// 检测可寻址地址是否重复 // 检测可寻址地址是否重复
if (AssetBundleGrouperSettingData.Setting.EnableAddressable) if (AssetBundleCollectorSettingData.Setting.EnableAddressable)
{ {
HashSet<string> adressTemper = new HashSet<string>(); HashSet<string> adressTemper = new HashSet<string>();
foreach (var collectInfoPair in result) foreach (var collectInfoPair in result)
@ -155,11 +155,11 @@ namespace YooAsset.Editor
return result.Values.ToList(); return result.Values.ToList();
} }
private CollectAssetInfo CreateCollectAssetInfo(AssetBundleGrouper grouper, string assetPath, bool isRawAsset) private CollectAssetInfo CreateCollectAssetInfo(AssetBundleCollectorGroup group, string assetPath, bool isRawAsset)
{ {
string address = GetAddress(grouper, assetPath); string address = GetAddress(group, assetPath);
string bundleName = GetBundleName(grouper, assetPath); string bundleName = GetBundleName(group, assetPath);
List<string> assetTags = GetAssetTags(grouper); List<string> assetTags = GetAssetTags(group);
CollectAssetInfo collectAssetInfo = new CollectAssetInfo(CollectorType, bundleName, address, assetPath, assetTags, isRawAsset); CollectAssetInfo collectAssetInfo = new CollectAssetInfo(CollectorType, bundleName, address, assetPath, assetTags, isRawAsset);
collectAssetInfo.DependAssets = GetAllDependencies(assetPath); collectAssetInfo.DependAssets = GetAllDependencies(assetPath);
return collectAssetInfo; return collectAssetInfo;
@ -186,7 +186,7 @@ namespace YooAsset.Editor
private bool IsCollectAsset(string assetPath) private bool IsCollectAsset(string assetPath)
{ {
// 如果收集全路径着色器 // 如果收集全路径着色器
if (AssetBundleGrouperSettingData.Setting.AutoCollectShaders) if (AssetBundleCollectorSettingData.Setting.AutoCollectShaders)
{ {
Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath); Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
if (assetType == typeof(UnityEngine.Shader)) if (assetType == typeof(UnityEngine.Shader))
@ -194,41 +194,41 @@ namespace YooAsset.Editor
} }
// 根据规则设置过滤资源文件 // 根据规则设置过滤资源文件
IFilterRule filterRuleInstance = AssetBundleGrouperSettingData.GetFilterRuleInstance(FilterRuleName); IFilterRule filterRuleInstance = AssetBundleCollectorSettingData.GetFilterRuleInstance(FilterRuleName);
return filterRuleInstance.IsCollectAsset(new FilterRuleData(assetPath)); return filterRuleInstance.IsCollectAsset(new FilterRuleData(assetPath));
} }
private string GetAddress(AssetBundleGrouper grouper, string assetPath) private string GetAddress(AssetBundleCollectorGroup group, string assetPath)
{ {
if (CollectorType != ECollectorType.MainAssetCollector) if (CollectorType != ECollectorType.MainAssetCollector)
return string.Empty; return string.Empty;
IAddressRule addressRuleInstance = AssetBundleGrouperSettingData.GetAddressRuleInstance(AddressRuleName); IAddressRule addressRuleInstance = AssetBundleCollectorSettingData.GetAddressRuleInstance(AddressRuleName);
string adressValue = addressRuleInstance.GetAssetAddress(new AddressRuleData(assetPath, CollectPath, grouper.GrouperName)); string adressValue = addressRuleInstance.GetAssetAddress(new AddressRuleData(assetPath, CollectPath, group.GroupName));
return adressValue; return adressValue;
} }
private string GetBundleName(AssetBundleGrouper grouper, string assetPath) private string GetBundleName(AssetBundleCollectorGroup group, string assetPath)
{ {
// 如果自动收集所有的着色器 // 如果自动收集所有的着色器
if (AssetBundleGrouperSettingData.Setting.AutoCollectShaders) if (AssetBundleCollectorSettingData.Setting.AutoCollectShaders)
{ {
System.Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath); System.Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
if (assetType == typeof(UnityEngine.Shader)) if (assetType == typeof(UnityEngine.Shader))
{ {
string bundleName = AssetBundleGrouperSettingData.Setting.ShadersBundleName; string bundleName = AssetBundleCollectorSettingData.Setting.ShadersBundleName;
return EditorTools.GetRegularPath(bundleName).ToLower(); return EditorTools.GetRegularPath(bundleName).ToLower();
} }
} }
// 根据规则设置获取资源包名称 // 根据规则设置获取资源包名称
{ {
IPackRule packRuleInstance = AssetBundleGrouperSettingData.GetPackRuleInstance(PackRuleName); IPackRule packRuleInstance = AssetBundleCollectorSettingData.GetPackRuleInstance(PackRuleName);
string bundleName = packRuleInstance.GetBundleName(new PackRuleData(assetPath, CollectPath, grouper.GrouperName)); string bundleName = packRuleInstance.GetBundleName(new PackRuleData(assetPath, CollectPath, group.GroupName));
return EditorTools.GetRegularPath(bundleName).ToLower(); return EditorTools.GetRegularPath(bundleName).ToLower();
} }
} }
private List<string> GetAssetTags(AssetBundleGrouper grouper) private List<string> GetAssetTags(AssetBundleCollectorGroup group)
{ {
List<string> tags = StringUtility.StringToStringList(grouper.AssetTags, ';'); List<string> tags = StringUtility.StringToStringList(group.AssetTags, ';');
List<string> temper = StringUtility.StringToStringList(AssetTags, ';'); List<string> temper = StringUtility.StringToStringList(AssetTags, ';');
tags.AddRange(temper); tags.AddRange(temper);
return tags; return tags;

View File

@ -8,14 +8,14 @@ using UnityEngine;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class AssetBundleGrouperConfig public class AssetBundleCollectorConfig
{ {
public const string XmlShader = "Shader"; public const string XmlShader = "Shader";
public const string XmlAutoCollectShader = "AutoCollectShader"; public const string XmlAutoCollectShader = "AutoCollectShader";
public const string XmlShaderBundleName = "ShaderBundleName"; public const string XmlShaderBundleName = "ShaderBundleName";
public const string XmlGrouper = "Grouper"; public const string XmlGroup = "Group";
public const string XmlGrouperName = "GrouperName"; public const string XmlGroupName = "GroupName";
public const string XmlGrouperDesc = "GrouperDesc"; public const string XmlGroupDesc = "GroupDesc";
public const string XmlCollector = "Collector"; public const string XmlCollector = "Collector";
public const string XmlCollectPath = "CollectPath"; public const string XmlCollectPath = "CollectPath";
public const string XmlCollectorType = "CollectType"; public const string XmlCollectorType = "CollectType";
@ -57,26 +57,26 @@ namespace YooAsset.Editor
} }
// 读取分组配置 // 读取分组配置
List<AssetBundleGrouper> grouperTemper = new List<AssetBundleGrouper>(); List<AssetBundleCollectorGroup> groupTemper = new List<AssetBundleCollectorGroup>();
var grouperNodeList = root.GetElementsByTagName(XmlGrouper); var groupNodeList = root.GetElementsByTagName(XmlGroup);
foreach (var grouperNode in grouperNodeList) foreach (var groupNode in groupNodeList)
{ {
XmlElement grouperElement = grouperNode as XmlElement; XmlElement groupElement = groupNode as XmlElement;
if (grouperElement.HasAttribute(XmlGrouperName) == false) if (groupElement.HasAttribute(XmlGroupName) == false)
throw new Exception($"Not found attribute {XmlGrouperName} in {XmlGrouper}"); throw new Exception($"Not found attribute {XmlGroupName} in {XmlGroup}");
if (grouperElement.HasAttribute(XmlGrouperDesc) == false) if (groupElement.HasAttribute(XmlGroupDesc) == false)
throw new Exception($"Not found attribute {XmlGrouperDesc} in {XmlGrouper}"); throw new Exception($"Not found attribute {XmlGroupDesc} in {XmlGroup}");
if (grouperElement.HasAttribute(XmlAssetTags) == false) if (groupElement.HasAttribute(XmlAssetTags) == false)
throw new Exception($"Not found attribute {XmlAssetTags} in {XmlGrouper}"); throw new Exception($"Not found attribute {XmlAssetTags} in {XmlGroup}");
AssetBundleGrouper grouper = new AssetBundleGrouper(); AssetBundleCollectorGroup group = new AssetBundleCollectorGroup();
grouper.GrouperName = grouperElement.GetAttribute(XmlGrouperName); group.GroupName = groupElement.GetAttribute(XmlGroupName);
grouper.GrouperDesc = grouperElement.GetAttribute(XmlGrouperDesc); group.GroupDesc = groupElement.GetAttribute(XmlGroupDesc);
grouper.AssetTags = grouperElement.GetAttribute(XmlAssetTags); group.AssetTags = groupElement.GetAttribute(XmlAssetTags);
grouperTemper.Add(grouper); groupTemper.Add(group);
// 读取收集器配置 // 读取收集器配置
var collectorNodeList = grouperElement.GetElementsByTagName(XmlCollector); var collectorNodeList = groupElement.GetElementsByTagName(XmlCollector);
foreach (var collectorNode in collectorNodeList) foreach (var collectorNode in collectorNodeList)
{ {
XmlElement collectorElement = collectorNode as XmlElement; XmlElement collectorElement = collectorNode as XmlElement;
@ -100,16 +100,16 @@ namespace YooAsset.Editor
collector.PackRuleName = collectorElement.GetAttribute(XmlPackRule); collector.PackRuleName = collectorElement.GetAttribute(XmlPackRule);
collector.FilterRuleName = collectorElement.GetAttribute(XmlFilterRule); collector.FilterRuleName = collectorElement.GetAttribute(XmlFilterRule);
collector.AssetTags = collectorElement.GetAttribute(XmlAssetTags); ; collector.AssetTags = collectorElement.GetAttribute(XmlAssetTags); ;
grouper.Collectors.Add(collector); group.Collectors.Add(collector);
} }
} }
// 保存配置数据 // 保存配置数据
AssetBundleGrouperSettingData.ClearAll(); AssetBundleCollectorSettingData.ClearAll();
AssetBundleGrouperSettingData.Setting.AutoCollectShaders = autoCollectShaders; AssetBundleCollectorSettingData.Setting.AutoCollectShaders = autoCollectShaders;
AssetBundleGrouperSettingData.Setting.ShadersBundleName = shaderBundleName; AssetBundleCollectorSettingData.Setting.ShadersBundleName = shaderBundleName;
AssetBundleGrouperSettingData.Setting.Groupers.AddRange(grouperTemper); AssetBundleCollectorSettingData.Setting.Groups.AddRange(groupTemper);
AssetBundleGrouperSettingData.SaveFile(); AssetBundleCollectorSettingData.SaveFile();
Debug.Log($"导入配置完毕!"); Debug.Log($"导入配置完毕!");
} }
@ -132,20 +132,20 @@ namespace YooAsset.Editor
// 设置着色器配置 // 设置着色器配置
var shaderElement = xmlDoc.CreateElement(XmlShader); var shaderElement = xmlDoc.CreateElement(XmlShader);
shaderElement.SetAttribute(XmlAutoCollectShader, AssetBundleGrouperSettingData.Setting.AutoCollectShaders.ToString()); shaderElement.SetAttribute(XmlAutoCollectShader, AssetBundleCollectorSettingData.Setting.AutoCollectShaders.ToString());
shaderElement.SetAttribute(XmlShaderBundleName, AssetBundleGrouperSettingData.Setting.ShadersBundleName); shaderElement.SetAttribute(XmlShaderBundleName, AssetBundleCollectorSettingData.Setting.ShadersBundleName);
// 设置分组配置 // 设置分组配置
foreach (var grouper in AssetBundleGrouperSettingData.Setting.Groupers) foreach (var group in AssetBundleCollectorSettingData.Setting.Groups)
{ {
var grouperElement = xmlDoc.CreateElement(XmlGrouper); var groupElement = xmlDoc.CreateElement(XmlGroup);
grouperElement.SetAttribute(XmlGrouperName, grouper.GrouperName); groupElement.SetAttribute(XmlGroupName, group.GroupName);
grouperElement.SetAttribute(XmlGrouperDesc, grouper.GrouperDesc); groupElement.SetAttribute(XmlGroupDesc, group.GroupDesc);
grouperElement.SetAttribute(XmlAssetTags, grouper.AssetTags); groupElement.SetAttribute(XmlAssetTags, group.AssetTags);
root.AppendChild(grouperElement); root.AppendChild(groupElement);
// 设置收集器配置 // 设置收集器配置
foreach (var collector in grouper.Collectors) foreach (var collector in group.Collectors)
{ {
var collectorElement = xmlDoc.CreateElement(XmlCollector); var collectorElement = xmlDoc.CreateElement(XmlCollector);
collectorElement.SetAttribute(XmlCollectPath, collector.CollectPath); collectorElement.SetAttribute(XmlCollectPath, collector.CollectPath);
@ -154,7 +154,7 @@ namespace YooAsset.Editor
collectorElement.SetAttribute(XmlPackRule, collector.PackRuleName); collectorElement.SetAttribute(XmlPackRule, collector.PackRuleName);
collectorElement.SetAttribute(XmlFilterRule, collector.FilterRuleName); collectorElement.SetAttribute(XmlFilterRule, collector.FilterRuleName);
collectorElement.SetAttribute(XmlAssetTags, collector.AssetTags); collectorElement.SetAttribute(XmlAssetTags, collector.AssetTags);
grouperElement.AppendChild(collectorElement); groupElement.AppendChild(collectorElement);
} }
} }

View File

@ -8,17 +8,17 @@ using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
[Serializable] [Serializable]
public class AssetBundleGrouper public class AssetBundleCollectorGroup
{ {
/// <summary> /// <summary>
/// 分组名称 /// 分组名称
/// </summary> /// </summary>
public string GrouperName = string.Empty; public string GroupName = string.Empty;
/// <summary> /// <summary>
/// 分组描述 /// 分组描述
/// </summary> /// </summary>
public string GrouperDesc = string.Empty; public string GroupDesc = string.Empty;
/// <summary> /// <summary>
/// 资源分类标签 /// 资源分类标签
@ -58,12 +58,12 @@ namespace YooAsset.Editor
if (result.ContainsKey(assetInfo.AssetPath) == false) if (result.ContainsKey(assetInfo.AssetPath) == false)
result.Add(assetInfo.AssetPath, assetInfo); result.Add(assetInfo.AssetPath, assetInfo);
else else
throw new Exception($"The collecting asset file is existed : {assetInfo.AssetPath} in grouper : {GrouperName}"); throw new Exception($"The collecting asset file is existed : {assetInfo.AssetPath} in group : {GroupName}");
} }
} }
// 检测可寻址地址是否重复 // 检测可寻址地址是否重复
if (AssetBundleGrouperSettingData.Setting.EnableAddressable) if (AssetBundleCollectorSettingData.Setting.EnableAddressable)
{ {
HashSet<string> adressTemper = new HashSet<string>(); HashSet<string> adressTemper = new HashSet<string>();
foreach (var collectInfoPair in result) foreach (var collectInfoPair in result)
@ -74,7 +74,7 @@ namespace YooAsset.Editor
if (adressTemper.Contains(address) == false) if (adressTemper.Contains(address) == false)
adressTemper.Add(address); adressTemper.Add(address);
else else
throw new Exception($"The address is existed : {address} in grouper : {GrouperName}"); throw new Exception($"The address is existed : {address} in group : {GroupName}");
} }
} }
} }

View File

@ -6,7 +6,7 @@ using UnityEngine;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class AssetBundleGrouperSetting : ScriptableObject public class AssetBundleCollectorSetting : ScriptableObject
{ {
/// <summary> /// <summary>
/// 是否启用可寻址资源定位 /// 是否启用可寻址资源定位
@ -26,7 +26,7 @@ namespace YooAsset.Editor
/// <summary> /// <summary>
/// 分组列表 /// 分组列表
/// </summary> /// </summary>
public List<AssetBundleGrouper> Groupers = new List<AssetBundleGrouper>(); public List<AssetBundleCollectorGroup> Groups = new List<AssetBundleCollectorGroup>();
/// <summary> /// <summary>
@ -34,9 +34,9 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public void CheckConfigError() public void CheckConfigError()
{ {
foreach (var grouper in Groupers) foreach (var group in Groups)
{ {
grouper.CheckConfigError(); group.CheckConfigError();
} }
} }
@ -48,15 +48,15 @@ namespace YooAsset.Editor
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000); Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000);
// 收集打包资源 // 收集打包资源
foreach (var grouper in Groupers) foreach (var group in Groups)
{ {
var temper = grouper.GetAllCollectAssets(); var temper = group.GetAllCollectAssets();
foreach (var assetInfo in temper) foreach (var assetInfo in temper)
{ {
if (result.ContainsKey(assetInfo.AssetPath) == false) if (result.ContainsKey(assetInfo.AssetPath) == false)
result.Add(assetInfo.AssetPath, assetInfo); result.Add(assetInfo.AssetPath, assetInfo);
else else
throw new Exception($"The collecting asset file is existed : {assetInfo.AssetPath} in grouper setting."); throw new Exception($"The collecting asset file is existed : {assetInfo.AssetPath} in group setting.");
} }
} }
@ -72,7 +72,7 @@ namespace YooAsset.Editor
if (adressTemper.Contains(address) == false) if (adressTemper.Contains(address) == false)
adressTemper.Add(address); adressTemper.Add(address);
else else
throw new Exception($"The address is existed : {address} in grouper setting."); throw new Exception($"The address is existed : {address} in group setting.");
} }
} }
} }

View File

@ -7,7 +7,7 @@ using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class AssetBundleGrouperSettingData public class AssetBundleCollectorSettingData
{ {
private static readonly Dictionary<string, System.Type> _cacheAddressRuleTypes = new Dictionary<string, System.Type>(); private static readonly Dictionary<string, System.Type> _cacheAddressRuleTypes = new Dictionary<string, System.Type>();
private static readonly Dictionary<string, IAddressRule> _cacheAddressRuleInstance = new Dictionary<string, IAddressRule>(); private static readonly Dictionary<string, IAddressRule> _cacheAddressRuleInstance = new Dictionary<string, IAddressRule>();
@ -24,8 +24,8 @@ namespace YooAsset.Editor
public static bool IsDirty { private set; get; } = false; public static bool IsDirty { private set; get; } = false;
private static AssetBundleGrouperSetting _setting = null; private static AssetBundleCollectorSetting _setting = null;
public static AssetBundleGrouperSetting Setting public static AssetBundleCollectorSetting Setting
{ {
get get
{ {
@ -106,12 +106,12 @@ namespace YooAsset.Editor
private static void LoadSettingData() private static void LoadSettingData()
{ {
// 加载配置文件 // 加载配置文件
string settingFilePath = $"{EditorTools.GetYooAssetSettingPath()}/{nameof(AssetBundleGrouperSetting)}.asset"; string settingFilePath = $"{EditorTools.GetYooAssetSettingPath()}/{nameof(AssetBundleCollectorSetting)}.asset";
_setting = AssetDatabase.LoadAssetAtPath<AssetBundleGrouperSetting>(settingFilePath); _setting = AssetDatabase.LoadAssetAtPath<AssetBundleCollectorSetting>(settingFilePath);
if (_setting == null) if (_setting == null)
{ {
Debug.LogWarning($"Create new {nameof(AssetBundleGrouperSetting)}.asset : {settingFilePath}"); Debug.LogWarning($"Create new {nameof(AssetBundleCollectorSetting)}.asset : {settingFilePath}");
_setting = ScriptableObject.CreateInstance<AssetBundleGrouperSetting>(); _setting = ScriptableObject.CreateInstance<AssetBundleCollectorSetting>();
EditorTools.CreateFileDirectory(settingFilePath); EditorTools.CreateFileDirectory(settingFilePath);
AssetDatabase.CreateAsset(Setting, settingFilePath); AssetDatabase.CreateAsset(Setting, settingFilePath);
AssetDatabase.SaveAssets(); AssetDatabase.SaveAssets();
@ -119,7 +119,7 @@ namespace YooAsset.Editor
} }
else else
{ {
Debug.Log($"Load {nameof(AssetBundleGrouperSetting)}.asset ok"); Debug.Log($"Load {nameof(AssetBundleCollectorSetting)}.asset ok");
} }
// IPackRule // IPackRule
@ -135,7 +135,7 @@ namespace YooAsset.Editor
typeof(PackDirectory), typeof(PackDirectory),
typeof(PackTopDirectory), typeof(PackTopDirectory),
typeof(PackCollector), typeof(PackCollector),
typeof(PackGrouper), typeof(PackGroup),
typeof(PackRawFile), typeof(PackRawFile),
}; };
@ -187,7 +187,7 @@ namespace YooAsset.Editor
{ {
typeof(AddressByFileName), typeof(AddressByFileName),
typeof(AddressByCollectorAndFileName), typeof(AddressByCollectorAndFileName),
typeof(AddressByGrouperAndFileName) typeof(AddressByGroupAndFileName)
}; };
TypeCache.TypeCollection collection = TypeCache.GetTypesDerivedFrom<IAddressRule>(); TypeCache.TypeCollection collection = TypeCache.GetTypesDerivedFrom<IAddressRule>();
@ -212,7 +212,7 @@ namespace YooAsset.Editor
IsDirty = false; IsDirty = false;
EditorUtility.SetDirty(Setting); EditorUtility.SetDirty(Setting);
AssetDatabase.SaveAssets(); AssetDatabase.SaveAssets();
Debug.Log($"{nameof(AssetBundleGrouperSetting)}.asset is saved!"); Debug.Log($"{nameof(AssetBundleCollectorSetting)}.asset is saved!");
} }
} }
@ -223,7 +223,7 @@ namespace YooAsset.Editor
{ {
Setting.AutoCollectShaders = false; Setting.AutoCollectShaders = false;
Setting.ShadersBundleName = string.Empty; Setting.ShadersBundleName = string.Empty;
Setting.Groupers.Clear(); Setting.Groups.Clear();
SaveFile(); SaveFile();
} }
@ -296,43 +296,43 @@ namespace YooAsset.Editor
} }
// 资源分组编辑相关 // 资源分组编辑相关
public static void CreateGrouper(string grouperName) public static void CreateGroup(string groupName)
{ {
AssetBundleGrouper grouper = new AssetBundleGrouper(); AssetBundleCollectorGroup group = new AssetBundleCollectorGroup();
grouper.GrouperName = grouperName; group.GroupName = groupName;
Setting.Groupers.Add(grouper); Setting.Groups.Add(group);
IsDirty = true; IsDirty = true;
} }
public static void RemoveGrouper(AssetBundleGrouper grouper) public static void RemoveGroup(AssetBundleCollectorGroup group)
{ {
if (Setting.Groupers.Remove(grouper)) if (Setting.Groups.Remove(group))
{ {
IsDirty = true; IsDirty = true;
} }
else else
{ {
Debug.LogWarning($"Failed remove grouper : {grouper.GrouperName}"); Debug.LogWarning($"Failed remove group : {group.GroupName}");
} }
} }
public static void ModifyGrouper(AssetBundleGrouper grouper) public static void ModifyGroup(AssetBundleCollectorGroup group)
{ {
if (grouper != null) if (group != null)
{ {
IsDirty = true; IsDirty = true;
} }
} }
// 资源收集器编辑相关 // 资源收集器编辑相关
public static void CreateCollector(AssetBundleGrouper grouper, string collectPath) public static void CreateCollector(AssetBundleCollectorGroup group, string collectPath)
{ {
AssetBundleCollector collector = new AssetBundleCollector(); AssetBundleCollector collector = new AssetBundleCollector();
collector.CollectPath = collectPath; collector.CollectPath = collectPath;
grouper.Collectors.Add(collector); group.Collectors.Add(collector);
IsDirty = true; IsDirty = true;
} }
public static void RemoveCollector(AssetBundleGrouper grouper, AssetBundleCollector collector) public static void RemoveCollector(AssetBundleCollectorGroup group, AssetBundleCollector collector)
{ {
if (grouper.Collectors.Remove(collector)) if (group.Collectors.Remove(collector))
{ {
IsDirty = true; IsDirty = true;
} }
@ -341,9 +341,9 @@ namespace YooAsset.Editor
Debug.LogWarning($"Failed remove collector : {collector.CollectPath}"); Debug.LogWarning($"Failed remove collector : {collector.CollectPath}");
} }
} }
public static void ModifyCollector(AssetBundleGrouper grouper, AssetBundleCollector collector) public static void ModifyCollector(AssetBundleCollectorGroup group, AssetBundleCollector collector)
{ {
if (grouper != null && collector != null) if (group != null && collector != null)
{ {
IsDirty = true; IsDirty = true;
} }

View File

@ -9,12 +9,12 @@ using UnityEngine.UIElements;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class AssetBundleGrouperWindow : EditorWindow public class AssetBundleCollectorWindow : EditorWindow
{ {
[MenuItem("YooAsset/AssetBundle Grouper", false, 101)] [MenuItem("YooAsset/AssetBundle Collector", false, 101)]
public static void ShowExample() public static void ShowExample()
{ {
AssetBundleGrouperWindow window = GetWindow<AssetBundleGrouperWindow>("资源包分组工具", true, EditorDefine.DockedWindowTypes); AssetBundleCollectorWindow window = GetWindow<AssetBundleCollectorWindow>("资源包收集工具", true, EditorDefine.DockedWindowTypes);
window.minSize = new Vector2(800, 600); window.minSize = new Vector2(800, 600);
} }
@ -22,15 +22,15 @@ namespace YooAsset.Editor
private List<string> _addressRuleList; private List<string> _addressRuleList;
private List<string> _packRuleList; private List<string> _packRuleList;
private List<string> _filterRuleList; private List<string> _filterRuleList;
private ListView _grouperListView; private ListView _groupListView;
private ScrollView _collectorScrollView; private ScrollView _collectorScrollView;
private Toggle _enableAddressableToogle; private Toggle _enableAddressableToogle;
private Toggle _autoCollectShaderToogle; private Toggle _autoCollectShaderToogle;
private TextField _shaderBundleNameTxt; private TextField _shaderBundleNameTxt;
private TextField _grouperNameTxt; private TextField _groupNameTxt;
private TextField _grouperDescTxt; private TextField _groupDescTxt;
private TextField _grouperAssetTagsTxt; private TextField _groupAssetTagsTxt;
private VisualElement _grouperContainer; private VisualElement _groupContainer;
public void CreateGUI() public void CreateGUI()
{ {
@ -45,17 +45,17 @@ namespace YooAsset.Editor
$"{nameof(ECollectorType.StaticAssetCollector)}", $"{nameof(ECollectorType.StaticAssetCollector)}",
$"{nameof(ECollectorType.DependAssetCollector)}" $"{nameof(ECollectorType.DependAssetCollector)}"
}; };
_addressRuleList = AssetBundleGrouperSettingData.GetAddressRuleNames(); _addressRuleList = AssetBundleCollectorSettingData.GetAddressRuleNames();
_packRuleList = AssetBundleGrouperSettingData.GetPackRuleNames(); _packRuleList = AssetBundleCollectorSettingData.GetPackRuleNames();
_filterRuleList = AssetBundleGrouperSettingData.GetFilterRuleNames(); _filterRuleList = AssetBundleCollectorSettingData.GetFilterRuleNames();
// 加载布局文件 // 加载布局文件
string rootPath = EditorTools.GetYooAssetSourcePath(); string rootPath = EditorTools.GetYooAssetSourcePath();
string uxml = $"{rootPath}/Editor/AssetBundleGrouper/{nameof(AssetBundleGrouperWindow)}.uxml"; string uxml = $"{rootPath}/Editor/AssetBundleCollector/{nameof(AssetBundleCollectorWindow)}.uxml";
var visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml); var visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
if (visualAsset == null) if (visualAsset == null)
{ {
Debug.LogError($"Not found {nameof(AssetBundleGrouperWindow)}.uxml : {uxml}"); Debug.LogError($"Not found {nameof(AssetBundleCollectorWindow)}.uxml : {uxml}");
return; return;
} }
visualAsset.CloneTree(root); visualAsset.CloneTree(root);
@ -72,75 +72,75 @@ namespace YooAsset.Editor
_enableAddressableToogle = root.Q<Toggle>("EnableAddressable"); _enableAddressableToogle = root.Q<Toggle>("EnableAddressable");
_enableAddressableToogle.RegisterValueChangedCallback(evt => _enableAddressableToogle.RegisterValueChangedCallback(evt =>
{ {
AssetBundleGrouperSettingData.ModifyAddressable(evt.newValue); AssetBundleCollectorSettingData.ModifyAddressable(evt.newValue);
}); });
_autoCollectShaderToogle = root.Q<Toggle>("AutoCollectShader"); _autoCollectShaderToogle = root.Q<Toggle>("AutoCollectShader");
_autoCollectShaderToogle.RegisterValueChangedCallback(evt => _autoCollectShaderToogle.RegisterValueChangedCallback(evt =>
{ {
AssetBundleGrouperSettingData.ModifyShader(evt.newValue, _shaderBundleNameTxt.value); AssetBundleCollectorSettingData.ModifyShader(evt.newValue, _shaderBundleNameTxt.value);
_shaderBundleNameTxt.SetEnabled(evt.newValue); _shaderBundleNameTxt.SetEnabled(evt.newValue);
}); });
_shaderBundleNameTxt = root.Q<TextField>("ShaderBundleName"); _shaderBundleNameTxt = root.Q<TextField>("ShaderBundleName");
_shaderBundleNameTxt.RegisterValueChangedCallback(evt => _shaderBundleNameTxt.RegisterValueChangedCallback(evt =>
{ {
AssetBundleGrouperSettingData.ModifyShader(_autoCollectShaderToogle.value, evt.newValue); AssetBundleCollectorSettingData.ModifyShader(_autoCollectShaderToogle.value, evt.newValue);
}); });
// 分组列表相关 // 分组列表相关
_grouperListView = root.Q<ListView>("GrouperListView"); _groupListView = root.Q<ListView>("GroupListView");
_grouperListView.makeItem = MakeGrouperListViewItem; _groupListView.makeItem = MakeGroupListViewItem;
_grouperListView.bindItem = BindGrouperListViewItem; _groupListView.bindItem = BindGroupListViewItem;
#if UNITY_2020_1_OR_NEWER #if UNITY_2020_1_OR_NEWER
_grouperListView.onSelectionChange += GrouperListView_onSelectionChange; _groupListView.onSelectionChange += GroupListView_onSelectionChange;
#else #else
_grouperListView.onSelectionChanged += GrouperListView_onSelectionChange; _groupListView.onSelectionChanged += GroupListView_onSelectionChange;
#endif #endif
// 分组添加删除按钮 // 分组添加删除按钮
var grouperAddContainer = root.Q("GrouperAddContainer"); var groupAddContainer = root.Q("GroupAddContainer");
{ {
var addBtn = grouperAddContainer.Q<Button>("AddBtn"); var addBtn = groupAddContainer.Q<Button>("AddBtn");
addBtn.clicked += AddGrouperBtn_clicked; addBtn.clicked += AddGroupBtn_clicked;
var removeBtn = grouperAddContainer.Q<Button>("RemoveBtn"); var removeBtn = groupAddContainer.Q<Button>("RemoveBtn");
removeBtn.clicked += RemoveGrouperBtn_clicked; removeBtn.clicked += RemoveGroupBtn_clicked;
} }
// 分组容器 // 分组容器
_grouperContainer = root.Q("GrouperContainer"); _groupContainer = root.Q("GroupContainer");
// 分组名称 // 分组名称
_grouperNameTxt = root.Q<TextField>("GrouperName"); _groupNameTxt = root.Q<TextField>("GroupName");
_grouperNameTxt.RegisterValueChangedCallback(evt => _groupNameTxt.RegisterValueChangedCallback(evt =>
{ {
var selectGrouper = _grouperListView.selectedItem as AssetBundleGrouper; var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
if (selectGrouper != null) if (selectGroup != null)
{ {
selectGrouper.GrouperName = evt.newValue; selectGroup.GroupName = evt.newValue;
AssetBundleGrouperSettingData.ModifyGrouper(selectGrouper); AssetBundleCollectorSettingData.ModifyGroup(selectGroup);
} }
}); });
// 分组备注 // 分组备注
_grouperDescTxt = root.Q<TextField>("GrouperDesc"); _groupDescTxt = root.Q<TextField>("GroupDesc");
_grouperDescTxt.RegisterValueChangedCallback(evt => _groupDescTxt.RegisterValueChangedCallback(evt =>
{ {
var selectGrouper = _grouperListView.selectedItem as AssetBundleGrouper; var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
if (selectGrouper != null) if (selectGroup != null)
{ {
selectGrouper.GrouperDesc = evt.newValue; selectGroup.GroupDesc = evt.newValue;
AssetBundleGrouperSettingData.ModifyGrouper(selectGrouper); AssetBundleCollectorSettingData.ModifyGroup(selectGroup);
} }
}); });
// 分组的资源标签 // 分组的资源标签
_grouperAssetTagsTxt = root.Q<TextField>("GrouperAssetTags"); _groupAssetTagsTxt = root.Q<TextField>("GroupAssetTags");
_grouperAssetTagsTxt.RegisterValueChangedCallback(evt => _groupAssetTagsTxt.RegisterValueChangedCallback(evt =>
{ {
var selectGrouper = _grouperListView.selectedItem as AssetBundleGrouper; var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
if (selectGrouper != null) if (selectGroup != null)
{ {
selectGrouper.AssetTags = evt.newValue; selectGroup.AssetTags = evt.newValue;
AssetBundleGrouperSettingData.ModifyGrouper(selectGrouper); AssetBundleCollectorSettingData.ModifyGroup(selectGroup);
} }
}); });
@ -166,26 +166,26 @@ namespace YooAsset.Editor
} }
public void OnDestroy() public void OnDestroy()
{ {
if (AssetBundleGrouperSettingData.IsDirty) if (AssetBundleCollectorSettingData.IsDirty)
AssetBundleGrouperSettingData.SaveFile(); AssetBundleCollectorSettingData.SaveFile();
} }
private void RefreshWindow() private void RefreshWindow()
{ {
_enableAddressableToogle.SetValueWithoutNotify(AssetBundleGrouperSettingData.Setting.EnableAddressable); _enableAddressableToogle.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.EnableAddressable);
_autoCollectShaderToogle.SetValueWithoutNotify(AssetBundleGrouperSettingData.Setting.AutoCollectShaders); _autoCollectShaderToogle.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.AutoCollectShaders);
_shaderBundleNameTxt.SetEnabled(AssetBundleGrouperSettingData.Setting.AutoCollectShaders); _shaderBundleNameTxt.SetEnabled(AssetBundleCollectorSettingData.Setting.AutoCollectShaders);
_shaderBundleNameTxt.SetValueWithoutNotify(AssetBundleGrouperSettingData.Setting.ShadersBundleName); _shaderBundleNameTxt.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.ShadersBundleName);
_grouperContainer.visible = false; _groupContainer.visible = false;
FillGrouperViewData(); FillGroupViewData();
} }
private void ExportBtn_clicked() private void ExportBtn_clicked()
{ {
string resultPath = EditorTools.OpenFolderPanel("Export XML", "Assets/"); string resultPath = EditorTools.OpenFolderPanel("Export XML", "Assets/");
if (resultPath != null) if (resultPath != null)
{ {
AssetBundleGrouperConfig.ExportXmlConfig($"{resultPath}/{nameof(AssetBundleGrouperConfig)}.xml"); AssetBundleCollectorConfig.ExportXmlConfig($"{resultPath}/{nameof(AssetBundleCollectorConfig)}.xml");
} }
} }
private void ImportBtn_clicked() private void ImportBtn_clicked()
@ -193,20 +193,20 @@ namespace YooAsset.Editor
string resultPath = EditorTools.OpenFilePath("Import XML", "Assets/", "xml"); string resultPath = EditorTools.OpenFilePath("Import XML", "Assets/", "xml");
if (resultPath != null) if (resultPath != null)
{ {
AssetBundleGrouperConfig.ImportXmlConfig(resultPath); AssetBundleCollectorConfig.ImportXmlConfig(resultPath);
RefreshWindow(); RefreshWindow();
} }
} }
// 分组列表相关 // 分组列表相关
private void FillGrouperViewData() private void FillGroupViewData()
{ {
_grouperListView.Clear(); _groupListView.Clear();
_grouperListView.ClearSelection(); _groupListView.ClearSelection();
_grouperListView.itemsSource = AssetBundleGrouperSettingData.Setting.Groupers; _groupListView.itemsSource = AssetBundleCollectorSettingData.Setting.Groups;
_grouperListView.Rebuild(); _groupListView.Rebuild();
} }
private VisualElement MakeGrouperListViewItem() private VisualElement MakeGroupListViewItem()
{ {
VisualElement element = new VisualElement(); VisualElement element = new VisualElement();
@ -221,57 +221,57 @@ namespace YooAsset.Editor
return element; return element;
} }
private void BindGrouperListViewItem(VisualElement element, int index) private void BindGroupListViewItem(VisualElement element, int index)
{ {
var grouper = AssetBundleGrouperSettingData.Setting.Groupers[index]; var group = AssetBundleCollectorSettingData.Setting.Groups[index];
// Grouper Name // Group Name
var textField1 = element.Q<Label>("Label1"); var textField1 = element.Q<Label>("Label1");
if (string.IsNullOrEmpty(grouper.GrouperDesc)) if (string.IsNullOrEmpty(group.GroupDesc))
textField1.text = grouper.GrouperName; textField1.text = group.GroupName;
else else
textField1.text = $"{grouper.GrouperName} ({grouper.GrouperDesc})"; textField1.text = $"{group.GroupName} ({group.GroupDesc})";
} }
private void GrouperListView_onSelectionChange(IEnumerable<object> objs) private void GroupListView_onSelectionChange(IEnumerable<object> objs)
{ {
FillCollectorViewData(); FillCollectorViewData();
} }
private void AddGrouperBtn_clicked() private void AddGroupBtn_clicked()
{ {
Undo.RecordObject(AssetBundleGrouperSettingData.Setting, "YooAsset AddGrouper"); Undo.RecordObject(AssetBundleCollectorSettingData.Setting, "YooAsset AddGroup");
AssetBundleGrouperSettingData.CreateGrouper("Default Grouper"); AssetBundleCollectorSettingData.CreateGroup("Default Group");
FillGrouperViewData(); FillGroupViewData();
} }
private void RemoveGrouperBtn_clicked() private void RemoveGroupBtn_clicked()
{ {
var selectGrouper = _grouperListView.selectedItem as AssetBundleGrouper; var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
if (selectGrouper == null) if (selectGroup == null)
return; return;
Undo.RecordObject(AssetBundleGrouperSettingData.Setting, "YooAsset RemoveGrouper"); Undo.RecordObject(AssetBundleCollectorSettingData.Setting, "YooAsset RemoveGroup");
AssetBundleGrouperSettingData.RemoveGrouper(selectGrouper); AssetBundleCollectorSettingData.RemoveGroup(selectGroup);
FillGrouperViewData(); FillGroupViewData();
} }
// 收集列表相关 // 收集列表相关
private void FillCollectorViewData() private void FillCollectorViewData()
{ {
var selectGrouper = _grouperListView.selectedItem as AssetBundleGrouper; var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
if (selectGrouper == null) if (selectGroup == null)
{ {
_grouperContainer.visible = false; _groupContainer.visible = false;
return; return;
} }
_grouperContainer.visible = true; _groupContainer.visible = true;
_grouperNameTxt.SetValueWithoutNotify(selectGrouper.GrouperName); _groupNameTxt.SetValueWithoutNotify(selectGroup.GroupName);
_grouperDescTxt.SetValueWithoutNotify(selectGrouper.GrouperDesc); _groupDescTxt.SetValueWithoutNotify(selectGroup.GroupDesc);
_grouperAssetTagsTxt.SetValueWithoutNotify(selectGrouper.AssetTags); _groupAssetTagsTxt.SetValueWithoutNotify(selectGroup.AssetTags);
// 填充数据 // 填充数据
_collectorScrollView.Clear(); _collectorScrollView.Clear();
for (int i = 0; i < selectGrouper.Collectors.Count; i++) for (int i = 0; i < selectGroup.Collectors.Count; i++)
{ {
VisualElement element = MakeCollectorListViewItem(); VisualElement element = MakeCollectorListViewItem();
BindCollectorListViewItem(element, i); BindCollectorListViewItem(element, i);
@ -391,11 +391,11 @@ namespace YooAsset.Editor
} }
private void BindCollectorListViewItem(VisualElement element, int index) private void BindCollectorListViewItem(VisualElement element, int index)
{ {
var selectGrouper = _grouperListView.selectedItem as AssetBundleGrouper; var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
if (selectGrouper == null) if (selectGroup == null)
return; return;
var collector = selectGrouper.Collectors[index]; var collector = selectGroup.Collectors[index];
var collectObject = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(collector.CollectPath); var collectObject = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(collector.CollectPath);
if (collectObject != null) if (collectObject != null)
collectObject.name = collector.CollectPath; collectObject.name = collector.CollectPath;
@ -405,7 +405,7 @@ namespace YooAsset.Editor
foldout.RegisterValueChangedCallback(evt => foldout.RegisterValueChangedCallback(evt =>
{ {
if (evt.newValue) if (evt.newValue)
RefreshFoldout(foldout, selectGrouper, collector); RefreshFoldout(foldout, selectGroup, collector);
else else
foldout.Clear(); foldout.Clear();
}); });
@ -424,10 +424,10 @@ namespace YooAsset.Editor
{ {
collector.CollectPath = AssetDatabase.GetAssetPath(evt.newValue); collector.CollectPath = AssetDatabase.GetAssetPath(evt.newValue);
objectField1.value.name = collector.CollectPath; objectField1.value.name = collector.CollectPath;
AssetBundleGrouperSettingData.ModifyCollector(selectGrouper, collector); AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
if (foldout.value) if (foldout.value)
{ {
RefreshFoldout(foldout, selectGrouper, collector); RefreshFoldout(foldout, selectGroup, collector);
} }
}); });
@ -437,10 +437,10 @@ namespace YooAsset.Editor
popupField0.RegisterValueChangedCallback(evt => popupField0.RegisterValueChangedCallback(evt =>
{ {
collector.CollectorType = StringUtility.NameToEnum<ECollectorType>(evt.newValue); collector.CollectorType = StringUtility.NameToEnum<ECollectorType>(evt.newValue);
AssetBundleGrouperSettingData.ModifyCollector(selectGrouper, collector); AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
if (foldout.value) if (foldout.value)
{ {
RefreshFoldout(foldout, selectGrouper, collector); RefreshFoldout(foldout, selectGroup, collector);
} }
}); });
@ -452,10 +452,10 @@ namespace YooAsset.Editor
popupField1.RegisterValueChangedCallback(evt => popupField1.RegisterValueChangedCallback(evt =>
{ {
collector.AddressRuleName = evt.newValue; collector.AddressRuleName = evt.newValue;
AssetBundleGrouperSettingData.ModifyCollector(selectGrouper, collector); AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
if (foldout.value) if (foldout.value)
{ {
RefreshFoldout(foldout, selectGrouper, collector); RefreshFoldout(foldout, selectGroup, collector);
} }
}); });
} }
@ -466,10 +466,10 @@ namespace YooAsset.Editor
popupField2.RegisterValueChangedCallback(evt => popupField2.RegisterValueChangedCallback(evt =>
{ {
collector.PackRuleName = evt.newValue; collector.PackRuleName = evt.newValue;
AssetBundleGrouperSettingData.ModifyCollector(selectGrouper, collector); AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
if (foldout.value) if (foldout.value)
{ {
RefreshFoldout(foldout, selectGrouper, collector); RefreshFoldout(foldout, selectGroup, collector);
} }
}); });
@ -479,10 +479,10 @@ namespace YooAsset.Editor
popupField3.RegisterValueChangedCallback(evt => popupField3.RegisterValueChangedCallback(evt =>
{ {
collector.FilterRuleName = evt.newValue; collector.FilterRuleName = evt.newValue;
AssetBundleGrouperSettingData.ModifyCollector(selectGrouper, collector); AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
if (foldout.value) if (foldout.value)
{ {
RefreshFoldout(foldout, selectGrouper, collector); RefreshFoldout(foldout, selectGroup, collector);
} }
}); });
@ -492,17 +492,17 @@ namespace YooAsset.Editor
textFiled1.RegisterValueChangedCallback(evt => textFiled1.RegisterValueChangedCallback(evt =>
{ {
collector.AssetTags = evt.newValue; collector.AssetTags = evt.newValue;
AssetBundleGrouperSettingData.ModifyCollector(selectGrouper, collector); AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
}); });
} }
private void RefreshFoldout(Foldout foldout, AssetBundleGrouper grouper, AssetBundleCollector collector) private void RefreshFoldout(Foldout foldout, AssetBundleCollectorGroup group, AssetBundleCollector collector)
{ {
// 清空旧元素 // 清空旧元素
foldout.Clear(); foldout.Clear();
if (collector.IsValid() == false) if (collector.IsValid() == false)
{ {
Debug.LogWarning($"The collector is invalid : {collector.CollectPath} in grouper : {grouper.GrouperName}"); Debug.LogWarning($"The collector is invalid : {collector.CollectPath} in group : {group.GroupName}");
return; return;
} }
@ -512,7 +512,7 @@ namespace YooAsset.Editor
try try
{ {
collectAssetInfos = collector.GetAllCollectAssets(grouper); collectAssetInfos = collector.GetAllCollectAssets(group);
} }
catch (System.Exception e) catch (System.Exception e)
{ {
@ -530,8 +530,8 @@ namespace YooAsset.Editor
string showInfo = collectAssetInfo.AssetPath; string showInfo = collectAssetInfo.AssetPath;
if (_enableAddressableToogle.value) if (_enableAddressableToogle.value)
{ {
IAddressRule instance = AssetBundleGrouperSettingData.GetAddressRuleInstance(collector.AddressRuleName); IAddressRule instance = AssetBundleCollectorSettingData.GetAddressRuleInstance(collector.AddressRuleName);
AddressRuleData ruleData = new AddressRuleData(collectAssetInfo.AssetPath, collector.CollectPath, grouper.GrouperName); AddressRuleData ruleData = new AddressRuleData(collectAssetInfo.AssetPath, collector.CollectPath, group.GroupName);
string addressValue = instance.GetAssetAddress(ruleData); string addressValue = instance.GetAssetAddress(ruleData);
showInfo = $"[{addressValue}] {showInfo}"; showInfo = $"[{addressValue}] {showInfo}";
} }
@ -548,21 +548,21 @@ namespace YooAsset.Editor
} }
private void AddCollectorBtn_clicked() private void AddCollectorBtn_clicked()
{ {
var selectGrouper = _grouperListView.selectedItem as AssetBundleGrouper; var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
if (selectGrouper == null) if (selectGroup == null)
return; return;
AssetBundleGrouperSettingData.CreateCollector(selectGrouper, string.Empty); AssetBundleCollectorSettingData.CreateCollector(selectGroup, string.Empty);
FillCollectorViewData(); FillCollectorViewData();
} }
private void RemoveCollectorBtn_clicked(AssetBundleCollector selectCollector) private void RemoveCollectorBtn_clicked(AssetBundleCollector selectCollector)
{ {
var selectGrouper = _grouperListView.selectedItem as AssetBundleGrouper; var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
if (selectGrouper == null) if (selectGroup == null)
return; return;
if (selectCollector == null) if (selectCollector == null)
return; return;
AssetBundleGrouperSettingData.RemoveCollector(selectGrouper, selectCollector); AssetBundleCollectorSettingData.RemoveCollector(selectGroup, selectCollector);
FillCollectorViewData(); FillCollectorViewData();
} }

View File

@ -5,8 +5,8 @@
</uie:Toolbar> </uie:Toolbar>
<ui:VisualElement name="ContentContainer" style="flex-grow: 1; flex-direction: row;"> <ui:VisualElement name="ContentContainer" style="flex-grow: 1; flex-direction: row;">
<ui:VisualElement name="LeftContainer" 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;"> <ui:VisualElement name="LeftContainer" 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;">
<ui:ListView focusable="true" name="GrouperListView" item-height="20" virtualization-method="DynamicHeight" style="flex-grow: 1;" /> <ui:ListView focusable="true" name="GroupListView" item-height="20" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
<ui:VisualElement name="GrouperAddContainer" style="height: 20px; flex-direction: row; justify-content: center;"> <ui:VisualElement name="GroupAddContainer" style="height: 20px; flex-direction: row; justify-content: center;">
<ui:Button text=" - " display-tooltip-when-elided="true" name="RemoveBtn" /> <ui:Button text=" - " display-tooltip-when-elided="true" name="RemoveBtn" />
<ui:Button text=" + " display-tooltip-when-elided="true" name="AddBtn" /> <ui:Button text=" + " display-tooltip-when-elided="true" name="AddBtn" />
</ui:VisualElement> </ui:VisualElement>
@ -17,10 +17,10 @@
<ui:Toggle label="Auto Collect Shaders" name="AutoCollectShader" style="width: 196px; -unity-text-align: middle-left;" /> <ui:Toggle label="Auto Collect Shaders" name="AutoCollectShader" style="width: 196px; -unity-text-align: middle-left;" />
<ui:TextField picking-mode="Ignore" label="Shader Bundle Name" name="ShaderBundleName" style="flex-grow: 1; -unity-text-align: middle-left;" /> <ui:TextField picking-mode="Ignore" label="Shader Bundle Name" name="ShaderBundleName" style="flex-grow: 1; -unity-text-align: middle-left;" />
</ui:VisualElement> </ui:VisualElement>
<ui:VisualElement name="GrouperContainer" style="flex-grow: 1; border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px;"> <ui:VisualElement name="GroupContainer" style="flex-grow: 1; border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px;">
<ui:TextField picking-mode="Ignore" label="Grouper Name" name="GrouperName" /> <ui:TextField picking-mode="Ignore" label="Group Name" name="GroupName" />
<ui:TextField picking-mode="Ignore" label="Grouper Desc" name="GrouperDesc" /> <ui:TextField picking-mode="Ignore" label="Group Desc" name="GroupDesc" />
<ui:TextField picking-mode="Ignore" label="Grouper Asset Tags" name="GrouperAssetTags" /> <ui:TextField picking-mode="Ignore" label="Group Asset Tags" name="GroupAssetTags" />
<ui:VisualElement name="CollectorAddContainer" style="height: 20px; flex-direction: row-reverse;"> <ui:VisualElement name="CollectorAddContainer" style="height: 20px; flex-direction: row-reverse;">
<ui:Button text="[ + ]" display-tooltip-when-elided="true" name="AddBtn" /> <ui:Button text="[ + ]" display-tooltip-when-elided="true" name="AddBtn" />
</ui:VisualElement> </ui:VisualElement>

View File

@ -16,12 +16,12 @@ namespace YooAsset.Editor
/// <summary> /// <summary>
/// 以组名+文件名为定位地址 /// 以组名+文件名为定位地址
/// </summary> /// </summary>
public class AddressByGrouperAndFileName : IAddressRule public class AddressByGroupAndFileName : IAddressRule
{ {
string IAddressRule.GetAssetAddress(AddressRuleData data) string IAddressRule.GetAssetAddress(AddressRuleData data)
{ {
string fileName = Path.GetFileNameWithoutExtension(data.AssetPath); string fileName = Path.GetFileNameWithoutExtension(data.AssetPath);
return $"{data.GrouperName}_{fileName}"; return $"{data.GroupName}_{fileName}";
} }
} }

View File

@ -78,11 +78,11 @@ namespace YooAsset.Editor
/// 以分组名称作为资源包名 /// 以分组名称作为资源包名
/// 注意:收集的所有文件打进一个资源包 /// 注意:收集的所有文件打进一个资源包
/// </summary> /// </summary>
public class PackGrouper : IPackRule public class PackGroup : IPackRule
{ {
string IPackRule.GetBundleName(PackRuleData data) string IPackRule.GetBundleName(PackRuleData data)
{ {
return data.GrouperName; return data.GroupName;
} }
} }

View File

@ -5,13 +5,13 @@ namespace YooAsset.Editor
{ {
public string AssetPath; public string AssetPath;
public string CollectPath; public string CollectPath;
public string GrouperName; public string GroupName;
public AddressRuleData(string assetPath, string collectPath, string grouperName) public AddressRuleData(string assetPath, string collectPath, string groupName)
{ {
AssetPath = assetPath; AssetPath = assetPath;
CollectPath = collectPath; CollectPath = collectPath;
GrouperName = grouperName; GroupName = groupName;
} }
} }

View File

@ -5,19 +5,19 @@ namespace YooAsset.Editor
{ {
public string AssetPath; public string AssetPath;
public string CollectPath; public string CollectPath;
public string GrouperName; public string GroupName;
public PackRuleData(string assetPath) public PackRuleData(string assetPath)
{ {
AssetPath = assetPath; AssetPath = assetPath;
CollectPath = string.Empty; CollectPath = string.Empty;
GrouperName = string.Empty; GroupName = string.Empty;
} }
public PackRuleData(string assetPath, string collectPath, string grouperName) public PackRuleData(string assetPath, string collectPath, string groupName)
{ {
AssetPath = assetPath; AssetPath = assetPath;
CollectPath = collectPath; CollectPath = collectPath;
GrouperName = grouperName; GroupName = groupName;
} }
} }

View File

@ -7,7 +7,7 @@ namespace YooAsset.Editor
/// <summary> /// <summary>
/// 停靠窗口类型集合 /// 停靠窗口类型集合
/// </summary> /// </summary>
public static readonly Type[] DockedWindowTypes = { typeof(AssetBundleBuilderWindow), typeof(AssetBundleGrouperWindow), typeof(AssetBundleDebuggerWindow), typeof(AssetBundleReporterWindow)}; public static readonly Type[] DockedWindowTypes = { typeof(AssetBundleBuilderWindow), typeof(AssetBundleCollectorWindow), typeof(AssetBundleDebuggerWindow), typeof(AssetBundleReporterWindow)};
} }
/// <summary> /// <summary>

View File

@ -98,7 +98,7 @@ namespace YooAsset.Editor
List<string> allAssets = new List<string>(1000); List<string> allAssets = new List<string>(1000);
// 获取所有打包的资源 // 获取所有打包的资源
List<CollectAssetInfo> allCollectInfos = AssetBundleGrouperSettingData.Setting.GetAllCollectAssets(); List<CollectAssetInfo> allCollectInfos = AssetBundleCollectorSettingData.Setting.GetAllCollectAssets();
List<string> collectAssets = allCollectInfos.Select(t => t.AssetPath).ToList(); List<string> collectAssets = allCollectInfos.Select(t => t.AssetPath).ToList();
foreach (var assetPath in collectAssets) foreach (var assetPath in collectAssets)
{ {

View File

@ -4,7 +4,7 @@ using System.Collections.Generic;
namespace YooAsset namespace YooAsset
{ {
internal class DependAssetBundleGrouper internal class DependAssetBundleGroup
{ {
/// <summary> /// <summary>
/// 依赖的资源包加载器列表 /// 依赖的资源包加载器列表
@ -12,7 +12,7 @@ namespace YooAsset
private readonly List<AssetBundleLoaderBase> _dependBundles; private readonly List<AssetBundleLoaderBase> _dependBundles;
public DependAssetBundleGrouper(string assetPath) public DependAssetBundleGroup(string assetPath)
{ {
_dependBundles = AssetSystem.CreateDependAssetBundleLoaders(assetPath); _dependBundles = AssetSystem.CreateDependAssetBundleLoaders(assetPath);
} }

View File

@ -6,14 +6,14 @@ namespace YooAsset
internal abstract class BundledProvider : ProviderBase internal abstract class BundledProvider : ProviderBase
{ {
protected AssetBundleLoaderBase OwnerBundle { private set; get; } protected AssetBundleLoaderBase OwnerBundle { private set; get; }
protected DependAssetBundleGrouper DependBundles { private set; get; } protected DependAssetBundleGroup DependBundles { private set; get; }
public BundledProvider(string assetPath, System.Type assetType) : base(assetPath, assetType) public BundledProvider(string assetPath, System.Type assetType) : base(assetPath, assetType)
{ {
OwnerBundle = AssetSystem.CreateOwnerAssetBundleLoader(assetPath); OwnerBundle = AssetSystem.CreateOwnerAssetBundleLoader(assetPath);
OwnerBundle.Reference(); OwnerBundle.Reference();
OwnerBundle.AddProvider(this); OwnerBundle.AddProvider(this);
DependBundles = new DependAssetBundleGrouper(assetPath); DependBundles = new DependAssetBundleGroup(assetPath);
DependBundles.Reference(); DependBundles.Reference();
} }
public override void Destroy() public override void Destroy()