Update AssetBundleCollector

编辑器支持分布式构建
pull/40/head
hevinci 2022-09-27 10:38:35 +08:00
parent 39c277b090
commit f0ac319a73
10 changed files with 658 additions and 210 deletions

View File

@ -132,7 +132,7 @@ namespace YooAsset.Editor
/// <summary>
/// 获取打包收集的资源文件
/// </summary>
public List<CollectAssetInfo> GetAllCollectAssets(EBuildMode buildMode, AssetBundleCollectorGroup group)
public List<CollectAssetInfo> GetAllCollectAssets(EBuildMode buildMode, bool enableAddressable, AssetBundleCollectorGroup group)
{
// 注意:模拟构建模式下只收集主资源
if (buildMode == EBuildMode.SimulateBuild)
@ -187,7 +187,7 @@ namespace YooAsset.Editor
}
// 检测可寻址地址是否重复
if (AssetBundleCollectorSettingData.Setting.EnableAddressable)
if (enableAddressable)
{
HashSet<string> adressTemper = new HashSet<string>();
foreach (var collectInfoPair in result)

View File

@ -10,14 +10,21 @@ namespace YooAsset.Editor
{
public class AssetBundleCollectorConfig
{
public const string ConfigVersion = "1.0";
public const string ConfigVersion = "2.0";
public const string XmlVersion = "Version";
public const string XmlCommon = "Common";
public const string XmlEnableAddressable = "AutoAddressable";
public const string XmlShowPackageView = "ShowPackageView";
public const string XmlPackage = "Package";
public const string XmlPackageName = "PackageName";
public const string XmlPackageDesc = "PackageDesc";
public const string XmlGroup = "Group";
public const string XmlGroupName = "GroupName";
public const string XmlGroupDesc = "GroupDesc";
public const string XmlCollector = "Collector";
public const string XmlCollectPath = "CollectPath";
public const string XmlCollectorGUID = "CollectGUID";
@ -39,85 +46,108 @@ namespace YooAsset.Editor
throw new Exception($"Only support xml : {filePath}");
// 加载配置文件
XmlDocument xml = new XmlDocument();
xml.Load(filePath);
XmlElement root = xml.DocumentElement;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filePath);
XmlElement root = xmlDoc.DocumentElement;
// 读取配置版本
string configVersion = root.GetAttribute(XmlVersion);
if (configVersion != ConfigVersion)
{
throw new Exception($"The config version is invalid : {configVersion}");
if (UpdateXmlConfig(xmlDoc) == false)
throw new Exception($"The config version update failed : {configVersion} -> {ConfigVersion}");
else
Debug.Log($"The config version update succeed : {configVersion} -> {ConfigVersion}");
}
// 读取公共配置
bool enableAddressable = false;
bool showPackageView = false;
var commonNodeList = root.GetElementsByTagName(XmlCommon);
if (commonNodeList.Count > 0)
{
XmlElement commonElement = commonNodeList[0] as XmlElement;
if (commonElement.HasAttribute(XmlEnableAddressable) == false)
throw new Exception($"Not found attribute {XmlEnableAddressable} in {XmlCommon}");
if (commonElement.HasAttribute(XmlShowPackageView) == false)
throw new Exception($"Not found attribute {XmlShowPackageView} in {XmlCommon}");
enableAddressable = commonElement.GetAttribute(XmlEnableAddressable) == "True" ? true : false;
showPackageView = commonElement.GetAttribute(XmlShowPackageView) == "True" ? true : false;
}
// 读取分组配置
List<AssetBundleCollectorGroup> groupTemper = new List<AssetBundleCollectorGroup>();
var groupNodeList = root.GetElementsByTagName(XmlGroup);
foreach (var groupNode in groupNodeList)
// 读取包裹配置
List<AssetBundleCollectorPackage> packages = new List<AssetBundleCollectorPackage>();
var packageNodeList = root.GetElementsByTagName(XmlPackage);
foreach (var packageNode in packageNodeList)
{
XmlElement groupElement = groupNode as XmlElement;
if (groupElement.HasAttribute(XmlGroupName) == false)
throw new Exception($"Not found attribute {XmlGroupName} in {XmlGroup}");
if (groupElement.HasAttribute(XmlGroupDesc) == false)
throw new Exception($"Not found attribute {XmlGroupDesc} in {XmlGroup}");
if (groupElement.HasAttribute(XmlAssetTags) == false)
throw new Exception($"Not found attribute {XmlAssetTags} in {XmlGroup}");
XmlElement packageElement = packageNode as XmlElement;
if (packageElement.HasAttribute(XmlPackageName) == false)
throw new Exception($"Not found attribute {XmlPackageName} in {XmlPackage}");
if (packageElement.HasAttribute(XmlPackageDesc) == false)
throw new Exception($"Not found attribute {XmlPackageDesc} in {XmlPackage}");
AssetBundleCollectorGroup group = new AssetBundleCollectorGroup();
group.GroupName = groupElement.GetAttribute(XmlGroupName);
group.GroupDesc = groupElement.GetAttribute(XmlGroupDesc);
group.AssetTags = groupElement.GetAttribute(XmlAssetTags);
groupTemper.Add(group);
AssetBundleCollectorPackage package = new AssetBundleCollectorPackage();
package.PackageName = packageElement.GetAttribute(XmlPackageName);
package.PackageDesc = packageElement.GetAttribute(XmlPackageDesc);
packages.Add(package);
// 读取收集器配置
var collectorNodeList = groupElement.GetElementsByTagName(XmlCollector);
foreach (var collectorNode in collectorNodeList)
// 读取分组配置
var groupNodeList = packageElement.GetElementsByTagName(XmlGroup);
foreach (var groupNode in groupNodeList)
{
XmlElement collectorElement = collectorNode as XmlElement;
if (collectorElement.HasAttribute(XmlCollectPath) == false)
throw new Exception($"Not found attribute {XmlCollectPath} in {XmlCollector}");
if (collectorElement.HasAttribute(XmlCollectorType) == false)
throw new Exception($"Not found attribute {XmlCollectorType} in {XmlCollector}");
if (collectorElement.HasAttribute(XmlAddressRule) == false)
throw new Exception($"Not found attribute {XmlAddressRule} in {XmlCollector}");
if (collectorElement.HasAttribute(XmlPackRule) == false)
throw new Exception($"Not found attribute {XmlPackRule} in {XmlCollector}");
if (collectorElement.HasAttribute(XmlFilterRule) == false)
throw new Exception($"Not found attribute {XmlFilterRule} in {XmlCollector}");
if (collectorElement.HasAttribute(XmlAssetTags) == false)
throw new Exception($"Not found attribute {XmlAssetTags} in {XmlCollector}");
XmlElement groupElement = groupNode as XmlElement;
if (groupElement.HasAttribute(XmlGroupName) == false)
throw new Exception($"Not found attribute {XmlGroupName} in {XmlGroup}");
if (groupElement.HasAttribute(XmlGroupDesc) == false)
throw new Exception($"Not found attribute {XmlGroupDesc} in {XmlGroup}");
if (groupElement.HasAttribute(XmlAssetTags) == false)
throw new Exception($"Not found attribute {XmlAssetTags} in {XmlGroup}");
string collectorGUID = string.Empty;
if (collectorElement.HasAttribute(XmlCollectorGUID))
collectorGUID = collectorElement.GetAttribute(XmlCollectorGUID);
AssetBundleCollectorGroup group = new AssetBundleCollectorGroup();
group.GroupName = groupElement.GetAttribute(XmlGroupName);
group.GroupDesc = groupElement.GetAttribute(XmlGroupDesc);
group.AssetTags = groupElement.GetAttribute(XmlAssetTags);
package.Groups.Add(group);
AssetBundleCollector collector = new AssetBundleCollector();
collector.CollectPath = collectorElement.GetAttribute(XmlCollectPath);
collector.CollectorGUID = collectorGUID;
collector.CollectorType = StringUtility.NameToEnum<ECollectorType>(collectorElement.GetAttribute(XmlCollectorType));
collector.AddressRuleName = collectorElement.GetAttribute(XmlAddressRule);
collector.PackRuleName = collectorElement.GetAttribute(XmlPackRule);
collector.FilterRuleName = collectorElement.GetAttribute(XmlFilterRule);
collector.AssetTags = collectorElement.GetAttribute(XmlAssetTags);
group.Collectors.Add(collector);
// 读取收集器配置
var collectorNodeList = groupElement.GetElementsByTagName(XmlCollector);
foreach (var collectorNode in collectorNodeList)
{
XmlElement collectorElement = collectorNode as XmlElement;
if (collectorElement.HasAttribute(XmlCollectPath) == false)
throw new Exception($"Not found attribute {XmlCollectPath} in {XmlCollector}");
if (collectorElement.HasAttribute(XmlCollectorGUID) == false)
throw new Exception($"Not found attribute {XmlCollectorGUID} in {XmlCollector}");
if (collectorElement.HasAttribute(XmlCollectorType) == false)
throw new Exception($"Not found attribute {XmlCollectorType} in {XmlCollector}");
if (collectorElement.HasAttribute(XmlAddressRule) == false)
throw new Exception($"Not found attribute {XmlAddressRule} in {XmlCollector}");
if (collectorElement.HasAttribute(XmlPackRule) == false)
throw new Exception($"Not found attribute {XmlPackRule} in {XmlCollector}");
if (collectorElement.HasAttribute(XmlFilterRule) == false)
throw new Exception($"Not found attribute {XmlFilterRule} in {XmlCollector}");
if (collectorElement.HasAttribute(XmlAssetTags) == false)
throw new Exception($"Not found attribute {XmlAssetTags} in {XmlCollector}");
AssetBundleCollector collector = new AssetBundleCollector();
collector.CollectPath = collectorElement.GetAttribute(XmlCollectPath);
collector.CollectorGUID = collectorElement.GetAttribute(XmlCollectorGUID);
collector.CollectorType = StringUtility.NameToEnum<ECollectorType>(collectorElement.GetAttribute(XmlCollectorType));
collector.AddressRuleName = collectorElement.GetAttribute(XmlAddressRule);
collector.PackRuleName = collectorElement.GetAttribute(XmlPackRule);
collector.FilterRuleName = collectorElement.GetAttribute(XmlFilterRule);
collector.AssetTags = collectorElement.GetAttribute(XmlAssetTags);
group.Collectors.Add(collector);
}
}
}
// 保存配置数据
AssetBundleCollectorSettingData.ClearAll();
AssetBundleCollectorSettingData.Setting.EnableAddressable = enableAddressable;
AssetBundleCollectorSettingData.Setting.Groups.AddRange(groupTemper);
AssetBundleCollectorSettingData.Setting.ShowPackageView = showPackageView;
AssetBundleCollectorSettingData.Setting.Packages.AddRange(packages);
AssetBundleCollectorSettingData.SaveFile();
Debug.Log($"导入配置完毕!");
}
@ -145,29 +175,39 @@ namespace YooAsset.Editor
// 设置公共配置
var commonElement = xmlDoc.CreateElement(XmlCommon);
commonElement.SetAttribute(XmlEnableAddressable, AssetBundleCollectorSettingData.Setting.EnableAddressable.ToString());
commonElement.SetAttribute(XmlShowPackageView, AssetBundleCollectorSettingData.Setting.ShowPackageView.ToString());
root.AppendChild(commonElement);
// 设置分组配置
foreach (var group in AssetBundleCollectorSettingData.Setting.Groups)
// 设置Package配置
foreach (var package in AssetBundleCollectorSettingData.Setting.Packages)
{
var groupElement = xmlDoc.CreateElement(XmlGroup);
groupElement.SetAttribute(XmlGroupName, group.GroupName);
groupElement.SetAttribute(XmlGroupDesc, group.GroupDesc);
groupElement.SetAttribute(XmlAssetTags, group.AssetTags);
root.AppendChild(groupElement);
var packageElement = xmlDoc.CreateElement(XmlPackage);
packageElement.SetAttribute(XmlPackageName, package.PackageName);
packageElement.SetAttribute(XmlPackageDesc, package.PackageDesc);
root.AppendChild(packageElement);
// 设置收集器配置
foreach (var collector in group.Collectors)
// 设置分组配置
foreach (var group in package.Groups)
{
var collectorElement = xmlDoc.CreateElement(XmlCollector);
collectorElement.SetAttribute(XmlCollectPath, collector.CollectPath);
collectorElement.SetAttribute(XmlCollectorGUID, collector.CollectorGUID);
collectorElement.SetAttribute(XmlCollectorType, collector.CollectorType.ToString());
collectorElement.SetAttribute(XmlAddressRule, collector.AddressRuleName);
collectorElement.SetAttribute(XmlPackRule, collector.PackRuleName);
collectorElement.SetAttribute(XmlFilterRule, collector.FilterRuleName);
collectorElement.SetAttribute(XmlAssetTags, collector.AssetTags);
groupElement.AppendChild(collectorElement);
var groupElement = xmlDoc.CreateElement(XmlGroup);
groupElement.SetAttribute(XmlGroupName, group.GroupName);
groupElement.SetAttribute(XmlGroupDesc, group.GroupDesc);
groupElement.SetAttribute(XmlAssetTags, group.AssetTags);
packageElement.AppendChild(groupElement);
// 设置收集器配置
foreach (var collector in group.Collectors)
{
var collectorElement = xmlDoc.CreateElement(XmlCollector);
collectorElement.SetAttribute(XmlCollectPath, collector.CollectPath);
collectorElement.SetAttribute(XmlCollectorGUID, collector.CollectorGUID);
collectorElement.SetAttribute(XmlCollectorType, collector.CollectorType.ToString());
collectorElement.SetAttribute(XmlAddressRule, collector.AddressRuleName);
collectorElement.SetAttribute(XmlPackRule, collector.PackRuleName);
collectorElement.SetAttribute(XmlFilterRule, collector.FilterRuleName);
collectorElement.SetAttribute(XmlAssetTags, collector.AssetTags);
groupElement.AppendChild(collectorElement);
}
}
}
@ -175,5 +215,65 @@ namespace YooAsset.Editor
xmlDoc.Save(savePath);
Debug.Log($"导出配置完毕!");
}
/// <summary>
/// 升级XML配置表
/// </summary>
private static bool UpdateXmlConfig(XmlDocument xmlDoc)
{
XmlElement root = xmlDoc.DocumentElement;
string configVersion = root.GetAttribute(XmlVersion);
if (configVersion == ConfigVersion)
return true;
// 1.0 -> 2.0
if (configVersion == "1.0")
{
// 添加公共元素属性
var commonNodeList = root.GetElementsByTagName(XmlCommon);
if (commonNodeList.Count > 0)
{
XmlElement commonElement = commonNodeList[0] as XmlElement;
if (commonElement.HasAttribute(XmlShowPackageView) == false)
commonElement.SetAttribute(XmlShowPackageView, "False");
}
// 添加包裹元素
var packageElement = xmlDoc.CreateElement(XmlPackage);
packageElement.SetAttribute(XmlPackageName, "Default Package");
packageElement.SetAttribute(XmlPackageDesc, string.Empty);
root.AppendChild(packageElement);
// 获取所有分组元素
var groupNodeList = root.GetElementsByTagName(XmlGroup);
List<XmlElement> temper = new List<XmlElement>(groupNodeList.Count);
foreach (var groupNode in groupNodeList)
{
XmlElement groupElement = groupNode as XmlElement;
var collectorNodeList = groupElement.GetElementsByTagName(XmlCollector);
foreach (var collectorNode in collectorNodeList)
{
XmlElement collectorElement = collectorNode as XmlElement;
if (collectorElement.HasAttribute(XmlCollectorGUID) == false)
collectorElement.SetAttribute(XmlCollectorGUID, string.Empty);
}
temper.Add(groupElement);
}
// 将分组元素转移至包裹元素下
foreach (var groupElement in temper)
{
root.RemoveChild(groupElement);
packageElement.AppendChild(groupElement);
}
// 更新版本
root.SetAttribute(XmlVersion, "2.0");
return UpdateXmlConfig(xmlDoc);
}
return false;
}
}
}

View File

@ -50,10 +50,26 @@ namespace YooAsset.Editor
}
}
/// <summary>
/// 修复配置错误
/// </summary>
public bool FixConfigError()
{
bool isFixed = false;
foreach (var collector in Collectors)
{
if (collector.FixConfigError())
{
isFixed = true;
}
}
return isFixed;
}
/// <summary>
/// 获取打包收集的资源文件
/// </summary>
public List<CollectAssetInfo> GetAllCollectAssets(EBuildMode buildMode)
public List<CollectAssetInfo> GetAllCollectAssets(EBuildMode buildMode, bool enableAddressable)
{
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000);
@ -67,7 +83,7 @@ namespace YooAsset.Editor
// 收集打包资源
foreach (var collector in Collectors)
{
var temper = collector.GetAllCollectAssets(buildMode, this);
var temper = collector.GetAllCollectAssets(buildMode, enableAddressable, this);
foreach (var assetInfo in temper)
{
if (result.ContainsKey(assetInfo.AssetPath) == false)
@ -78,7 +94,7 @@ namespace YooAsset.Editor
}
// 检测可寻址地址是否重复
if (AssetBundleCollectorSettingData.Setting.EnableAddressable)
if (enableAddressable)
{
HashSet<string> adressTemper = new HashSet<string>();
foreach (var collectInfoPair in result)

View File

@ -0,0 +1,125 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEditor;
namespace YooAsset.Editor
{
[Serializable]
public class AssetBundleCollectorPackage
{
/// <summary>
/// 包裹名称
/// </summary>
public string PackageName = string.Empty;
/// <summary>
/// 包裹描述
/// </summary>
public string PackageDesc = string.Empty;
/// <summary>
/// 分组列表
/// </summary>
public List<AssetBundleCollectorGroup> Groups = new List<AssetBundleCollectorGroup>();
/// <summary>
/// 检测配置错误
/// </summary>
public void CheckConfigError()
{
foreach (var group in Groups)
{
group.CheckConfigError();
}
}
/// <summary>
/// 修复配置错误
/// </summary>
public bool FixConfigError()
{
bool isFixed = false;
foreach (var group in Groups)
{
if (group.FixConfigError())
{
isFixed = true;
}
}
return isFixed;
}
/// <summary>
/// 获取打包收集的资源文件
/// </summary>
public List<CollectAssetInfo> GetAllCollectAssets(EBuildMode buildMode, bool enableAddressable)
{
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000);
// 收集打包资源
foreach (var group in Groups)
{
var temper = group.GetAllCollectAssets(buildMode, enableAddressable);
foreach (var assetInfo in temper)
{
if (result.ContainsKey(assetInfo.AssetPath) == false)
result.Add(assetInfo.AssetPath, assetInfo);
else
throw new Exception($"The collecting asset file is existed : {assetInfo.AssetPath}");
}
}
// 检测可寻址地址是否重复
if (enableAddressable)
{
HashSet<string> adressTemper = new HashSet<string>();
foreach (var collectInfoPair in result)
{
if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector)
{
string address = collectInfoPair.Value.Address;
if (adressTemper.Contains(address) == false)
adressTemper.Add(address);
else
throw new Exception($"The address is existed : {address}");
}
}
}
// 返回列表
return result.Values.ToList();
}
/// <summary>
/// 获取所有的资源标签
/// </summary>
public List<string> GetAllTags()
{
HashSet<string> result = new HashSet<string>();
foreach (var group in Groups)
{
List<string> groupTags = StringUtility.StringToStringList(group.AssetTags, ';');
foreach (var tag in groupTags)
{
if (result.Contains(tag) == false)
result.Add(tag);
}
foreach (var collector in group.Collectors)
{
List<string> collectorTags = StringUtility.StringToStringList(collector.AssetTags, ';');
foreach (var tag in collectorTags)
{
if (result.Contains(tag) == false)
result.Add(tag);
}
}
}
return result.ToList();
}
}
}

View File

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

View File

@ -8,25 +8,39 @@ namespace YooAsset.Editor
{
public class AssetBundleCollectorSetting : ScriptableObject
{
/// <summary>
/// 是否显示包裹视图
/// </summary>
public bool ShowPackageView = false;
/// <summary>
/// 是否启用可寻址资源定位
/// </summary>
public bool EnableAddressable = false;
/// <summary>
/// 分组列表
/// 包裹列表
/// </summary>
public List<AssetBundleCollectorGroup> Groups = new List<AssetBundleCollectorGroup>();
public List<AssetBundleCollectorPackage> Packages = new List<AssetBundleCollectorPackage>();
/// <summary>
/// 清空所有数据
/// </summary>
public void ClearAll()
{
EnableAddressable = false;
Packages.Clear();
}
/// <summary>
/// 检测配置错误
/// </summary>
public void CheckConfigError()
{
foreach (var group in Groups)
foreach (var package in Packages)
{
group.CheckConfigError();
package.CheckConfigError();
}
}
@ -35,88 +49,64 @@ namespace YooAsset.Editor
/// </summary>
public bool FixConfigError()
{
bool result = false;
foreach (var group in Groups)
bool isFixed = false;
foreach (var package in Packages)
{
foreach (var collector in group.Collectors)
if (package.FixConfigError())
{
bool isFixed = collector.FixConfigError();
if (isFixed)
{
result = true;
}
isFixed = true;
}
}
return result;
return isFixed;
}
/// <summary>
/// 获取所有的资源标签
/// </summary>
public List<string> GetAllTags()
public List<string> GetPackageAllTags(string packageName)
{
HashSet<string> result = new HashSet<string>();
foreach (var group in Groups)
foreach (var package in Packages)
{
List<string> groupTags = StringUtility.StringToStringList(group.AssetTags, ';');
foreach (var tag in groupTags)
if (package.PackageName == packageName)
{
if (result.Contains(tag) == false)
result.Add(tag);
}
foreach (var collector in group.Collectors)
{
List<string> collectorTags = StringUtility.StringToStringList(collector.AssetTags, ';');
foreach (var tag in collectorTags)
{
if (result.Contains(tag) == false)
result.Add(tag);
}
return package.GetAllTags();
}
}
return result.ToList();
Debug.LogWarning($"Not found package : {packageName}");
return new List<string>();
}
/// <summary>
/// 获取包裹收集的资源文件
/// </summary>
public List<CollectAssetInfo> GetPackageAssets(EBuildMode buildMode, string packageName)
{
if (string.IsNullOrEmpty(packageName))
throw new Exception("Build Package name is null or mepty !");
foreach (var package in Packages)
{
if (package.PackageName == packageName)
{
return package.GetAllCollectAssets(buildMode, EnableAddressable);
}
}
throw new Exception($"Not found collector pacakge : {packageName}");
}
/// <summary>
/// 获取打包收集的资源文件
/// 获取所有包裹收集的资源文件
/// </summary>
public List<CollectAssetInfo> GetAllCollectAssets(EBuildMode buildMode)
public List<CollectAssetInfo> GetAllPackageAssets(EBuildMode buildMode)
{
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000);
// 收集打包资源
foreach (var group in Groups)
List<CollectAssetInfo> result = new List<CollectAssetInfo>(1000);
foreach (var package in Packages)
{
var temper = group.GetAllCollectAssets(buildMode);
foreach (var assetInfo in temper)
{
if (result.ContainsKey(assetInfo.AssetPath) == false)
result.Add(assetInfo.AssetPath, assetInfo);
else
throw new Exception($"The collecting asset file is existed : {assetInfo.AssetPath}");
}
var temper = package.GetAllCollectAssets(buildMode, EnableAddressable);
result.AddRange(temper);
}
// 检测可寻址地址是否重复
if (EnableAddressable)
{
HashSet<string> adressTemper = new HashSet<string>();
foreach (var collectInfoPair in result)
{
if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector)
{
string address = collectInfoPair.Value.Address;
if (adressTemper.Contains(address) == false)
adressTemper.Add(address);
else
throw new Exception($"The address is existed : {address}");
}
}
}
// 返回列表
return result.Values.ToList();
return result;
}
}
}

View File

@ -256,14 +256,13 @@ namespace YooAsset.Editor
IsDirty = true;
}
}
/// <summary>
/// 清空所有数据
/// </summary>
public static void ClearAll()
{
Setting.EnableAddressable = false;
Setting.Groups.Clear();
Setting.ClearAll();
SaveFile();
}
@ -337,24 +336,56 @@ namespace YooAsset.Editor
}
}
// 可寻址编辑相关
// 公共参数编辑相关
public static void ModifyPackageView(bool showPackageView)
{
Setting.ShowPackageView = showPackageView;
IsDirty = true;
}
public static void ModifyAddressable(bool enableAddressable)
{
Setting.EnableAddressable = enableAddressable;
IsDirty = true;
}
// 资源包裹编辑相关
public static void CreatePackage(string packageName)
{
AssetBundleCollectorPackage package = new AssetBundleCollectorPackage();
package.PackageName = packageName;
Setting.Packages.Add(package);
IsDirty = true;
}
public static void RemovePackage(AssetBundleCollectorPackage package)
{
if (Setting.Packages.Remove(package))
{
IsDirty = true;
}
else
{
Debug.LogWarning($"Failed remove package : {package.PackageName}");
}
}
public static void ModifyPackage(AssetBundleCollectorPackage package)
{
if (package != null)
{
IsDirty = true;
}
}
// 资源分组编辑相关
public static void CreateGroup(string groupName)
public static void CreateGroup(AssetBundleCollectorPackage package, string groupName)
{
AssetBundleCollectorGroup group = new AssetBundleCollectorGroup();
group.GroupName = groupName;
Setting.Groups.Add(group);
package.Groups.Add(group);
IsDirty = true;
}
public static void RemoveGroup(AssetBundleCollectorGroup group)
public static void RemoveGroup(AssetBundleCollectorPackage package, AssetBundleCollectorGroup group)
{
if (Setting.Groups.Remove(group))
if (package.Groups.Remove(group))
{
IsDirty = true;
}
@ -363,18 +394,17 @@ namespace YooAsset.Editor
Debug.LogWarning($"Failed remove group : {group.GroupName}");
}
}
public static void ModifyGroup(AssetBundleCollectorGroup group)
public static void ModifyGroup(AssetBundleCollectorPackage package, AssetBundleCollectorGroup group)
{
if (group != null)
if (package != null && group != null)
{
IsDirty = true;
}
}
// 资源收集器编辑相关
public static void CreateCollector(AssetBundleCollectorGroup group)
public static void CreateCollector(AssetBundleCollectorGroup group, AssetBundleCollector collector)
{
AssetBundleCollector collector = new AssetBundleCollector();
group.Collectors.Add(collector);
IsDirty = true;
}
@ -400,9 +430,9 @@ namespace YooAsset.Editor
/// <summary>
/// 获取所有的资源标签
/// </summary>
public static string GetAllTags()
public static string GetPackageAllTags(string packageName)
{
var allTags = Setting.GetAllTags();
var allTags = Setting.GetPackageAllTags(packageName);
return string.Join(";", allTags);
}
}

View File

@ -24,15 +24,27 @@ namespace YooAsset.Editor
private List<string> _addressRuleList;
private List<string> _packRuleList;
private List<string> _filterRuleList;
private ListView _groupListView;
private ScrollView _collectorScrollView;
private PopupField<string> _activeRulePopupField;
private Toggle _showPackageToogle;
private Toggle _enableAddressableToogle;
private VisualElement _packageContainer;
private ListView _packageListView;
private TextField _packageNameTxt;
private TextField _packageDescTxt;
private VisualElement _groupContainer;
private ListView _groupListView;
private TextField _groupNameTxt;
private TextField _groupDescTxt;
private TextField _groupAssetTagsTxt;
private VisualElement _groupContainer;
private string _lastModifyGroup = string.Empty;
private VisualElement _collectorContainer;
private ScrollView _collectorScrollView;
private PopupField<string> _activeRulePopupField;
private int _lastModifyPackageIndex = 0;
private int _lastModifyGroupIndex = 0;
public void CreateGUI()
@ -62,6 +74,20 @@ namespace YooAsset.Editor
visualAsset.CloneTree(root);
// 公共设置相关
_showPackageToogle = root.Q<Toggle>("ShowPackages");
_showPackageToogle.RegisterValueChangedCallback(evt =>
{
AssetBundleCollectorSettingData.ModifyPackageView(evt.newValue);
RefreshWindow();
});
_enableAddressableToogle = root.Q<Toggle>("EnableAddressable");
_enableAddressableToogle.RegisterValueChangedCallback(evt =>
{
AssetBundleCollectorSettingData.ModifyAddressable(evt.newValue);
RefreshWindow();
});
// 配置修复按钮
var fixBtn = root.Q<Button>("FixButton");
fixBtn.clicked += FixBtn_clicked;
@ -76,12 +102,50 @@ namespace YooAsset.Editor
_saveButton = root.Q<Button>("SaveButton");
_saveButton.clicked += SaveBtn_clicked;
// 公共设置相关
_enableAddressableToogle = root.Q<Toggle>("EnableAddressable");
_enableAddressableToogle.RegisterValueChangedCallback(evt =>
// 包裹容器
_packageContainer = root.Q("PackageContainer");
// 包裹列表相关
_packageListView = root.Q<ListView>("PackageListView");
_packageListView.makeItem = MakePackageListViewItem;
_packageListView.bindItem = BindPackageListViewItem;
#if UNITY_2020_1_OR_NEWER
_packageListView.onSelectionChange += PackageListView_onSelectionChange;
#else
_packageListView.onSelectionChanged += PackageListView_onSelectionChange;
#endif
// 包裹添加删除按钮
var packageAddContainer = root.Q("PackageAddContainer");
{
AssetBundleCollectorSettingData.ModifyAddressable(evt.newValue);
RefreshWindow();
var addBtn = packageAddContainer.Q<Button>("AddBtn");
addBtn.clicked += AddPackageBtn_clicked;
var removeBtn = packageAddContainer.Q<Button>("RemoveBtn");
removeBtn.clicked += RemovePackageBtn_clicked;
}
// 包裹名称
_packageNameTxt = root.Q<TextField>("PackageName");
_packageNameTxt.RegisterValueChangedCallback(evt =>
{
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
if (selectPackage != null)
{
selectPackage.PackageName = evt.newValue;
AssetBundleCollectorSettingData.ModifyPackage(selectPackage);
}
});
// 包裹备注
_packageDescTxt = root.Q<TextField>("PackageDesc");
_packageDescTxt.RegisterValueChangedCallback(evt =>
{
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
if (selectPackage != null)
{
selectPackage.PackageDesc = evt.newValue;
AssetBundleCollectorSettingData.ModifyPackage(selectPackage);
}
});
// 分组列表相关
@ -110,11 +174,12 @@ namespace YooAsset.Editor
_groupNameTxt = root.Q<TextField>("GroupName");
_groupNameTxt.RegisterValueChangedCallback(evt =>
{
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
if (selectGroup != null)
if (selectPackage != null && selectGroup != null)
{
selectGroup.GroupName = evt.newValue;
AssetBundleCollectorSettingData.ModifyGroup(selectGroup);
AssetBundleCollectorSettingData.ModifyGroup(selectPackage, selectGroup);
}
});
@ -122,11 +187,12 @@ namespace YooAsset.Editor
_groupDescTxt = root.Q<TextField>("GroupDesc");
_groupDescTxt.RegisterValueChangedCallback(evt =>
{
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
if (selectGroup != null)
if (selectPackage != null && selectGroup != null)
{
selectGroup.GroupDesc = evt.newValue;
AssetBundleCollectorSettingData.ModifyGroup(selectGroup);
AssetBundleCollectorSettingData.ModifyGroup(selectPackage, selectGroup);
}
});
@ -134,14 +200,18 @@ namespace YooAsset.Editor
_groupAssetTagsTxt = root.Q<TextField>("GroupAssetTags");
_groupAssetTagsTxt.RegisterValueChangedCallback(evt =>
{
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
if (selectGroup != null)
if (selectPackage != null && selectGroup != null)
{
selectGroup.AssetTags = evt.newValue;
AssetBundleCollectorSettingData.ModifyGroup(selectGroup);
AssetBundleCollectorSettingData.ModifyGroup(selectPackage, selectGroup);
}
});
// 收集列表容器
_collectorContainer = root.Q("CollectorContainer");
// 收集列表相关
_collectorScrollView = root.Q<ScrollView>("CollectorScrollView");
_collectorScrollView.style.height = new Length(100, LengthUnit.Percent);
@ -163,11 +233,12 @@ namespace YooAsset.Editor
activeRuleContainer.Add(_activeRulePopupField);
_activeRulePopupField.RegisterValueChangedCallback(evt =>
{
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
if (selectGroup != null)
if (selectPackage != null && selectGroup != null)
{
selectGroup.ActiveRuleName = evt.newValue;
AssetBundleCollectorSettingData.ModifyGroup(selectGroup);
AssetBundleCollectorSettingData.ModifyGroup(selectPackage, selectGroup);
FillGroupViewData();
}
});
@ -208,10 +279,12 @@ namespace YooAsset.Editor
private void RefreshWindow()
{
_showPackageToogle.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.ShowPackageView);
_enableAddressableToogle.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.EnableAddressable);
_groupContainer.visible = false;
_collectorContainer.visible = false;
FillGroupViewData();
FillPackageViewData();
}
private void FixBtn_clicked()
{
@ -239,22 +312,97 @@ namespace YooAsset.Editor
AssetBundleCollectorSettingData.SaveFile();
}
// 包裹列表相关
private void FillPackageViewData()
{
_packageListView.Clear();
_packageListView.ClearSelection();
_packageListView.itemsSource = AssetBundleCollectorSettingData.Setting.Packages;
_packageListView.Rebuild();
if (_lastModifyPackageIndex >= 0 && _lastModifyPackageIndex < _packageListView.itemsSource.Count)
{
_packageListView.selectedIndex = _lastModifyPackageIndex;
}
if (_showPackageToogle.value)
_packageContainer.style.display = DisplayStyle.Flex;
else
_packageContainer.style.display = DisplayStyle.None;
}
private VisualElement MakePackageListViewItem()
{
VisualElement element = new VisualElement();
{
var label = new Label();
label.name = "Label1";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.flexGrow = 1f;
label.style.height = 20f;
element.Add(label);
}
return element;
}
private void BindPackageListViewItem(VisualElement element, int index)
{
var package = AssetBundleCollectorSettingData.Setting.Packages[index];
var textField1 = element.Q<Label>("Label1");
if (string.IsNullOrEmpty(package.PackageDesc))
textField1.text = package.PackageName;
else
textField1.text = $"{package.PackageName} ({package.PackageDesc})";
}
private void PackageListView_onSelectionChange(IEnumerable<object> objs)
{
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
if (selectPackage == null)
{
_groupContainer.visible = false;
_collectorContainer.visible = false;
return;
}
_groupContainer.visible = true;
_lastModifyPackageIndex = _packageListView.selectedIndex;
_packageNameTxt.SetValueWithoutNotify(selectPackage.PackageName);
_packageDescTxt.SetValueWithoutNotify(selectPackage.PackageDesc);
FillGroupViewData();
}
private void AddPackageBtn_clicked()
{
Undo.RecordObject(AssetBundleCollectorSettingData.Setting, "YooAsset.AssetBundleCollectorWindow AddPackage");
AssetBundleCollectorSettingData.CreatePackage("Default Package");
FillPackageViewData();
}
private void RemovePackageBtn_clicked()
{
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
if (selectPackage == null)
return;
Undo.RecordObject(AssetBundleCollectorSettingData.Setting, "YooAsset.AssetBundleCollectorWindow RemovePackage");
AssetBundleCollectorSettingData.RemovePackage(selectPackage);
FillPackageViewData();
}
// 分组列表相关
private void FillGroupViewData()
{
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
if (selectPackage == null)
return;
_groupListView.Clear();
_groupListView.ClearSelection();
_groupListView.itemsSource = AssetBundleCollectorSettingData.Setting.Groups;
_groupListView.itemsSource = selectPackage.Groups;
_groupListView.Rebuild();
for (int index = 0; index < AssetBundleCollectorSettingData.Setting.Groups.Count; index++)
if(_lastModifyGroupIndex >=0 && _lastModifyGroupIndex < _groupListView.itemsSource.Count)
{
var group = AssetBundleCollectorSettingData.Setting.Groups[index];
if (group.GroupName == _lastModifyGroup)
{
_groupListView.selectedIndex = index;
break;
}
_groupListView.selectedIndex = _lastModifyGroupIndex;
}
}
private VisualElement MakeGroupListViewItem()
@ -274,9 +422,12 @@ namespace YooAsset.Editor
}
private void BindGroupListViewItem(VisualElement element, int index)
{
var group = AssetBundleCollectorSettingData.Setting.Groups[index];
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
if (selectPackage == null)
return;
var group = selectPackage.Groups[index];
// Group Name
var textField1 = element.Q<Label>("Label1");
if (string.IsNullOrEmpty(group.GroupDesc))
textField1.text = group.GroupName;
@ -290,22 +441,44 @@ namespace YooAsset.Editor
}
private void GroupListView_onSelectionChange(IEnumerable<object> objs)
{
var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
if (selectGroup == null)
{
_collectorContainer.visible = false;
return;
}
_collectorContainer.visible = true;
_lastModifyGroupIndex = _groupListView.selectedIndex;
_activeRulePopupField.SetValueWithoutNotify(selectGroup.ActiveRuleName);
_groupNameTxt.SetValueWithoutNotify(selectGroup.GroupName);
_groupDescTxt.SetValueWithoutNotify(selectGroup.GroupDesc);
_groupAssetTagsTxt.SetValueWithoutNotify(selectGroup.AssetTags);
FillCollectorViewData();
}
private void AddGroupBtn_clicked()
{
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
if (selectPackage == null)
return;
Undo.RecordObject(AssetBundleCollectorSettingData.Setting, "YooAsset.AssetBundleCollectorWindow AddGroup");
AssetBundleCollectorSettingData.CreateGroup("Default Group");
AssetBundleCollectorSettingData.CreateGroup(selectPackage, "Default Group");
FillGroupViewData();
}
private void RemoveGroupBtn_clicked()
{
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
if (selectPackage == null)
return;
var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
if (selectGroup == null)
return;
Undo.RecordObject(AssetBundleCollectorSettingData.Setting, "YooAsset.AssetBundleCollectorWindow RemoveGroup");
AssetBundleCollectorSettingData.RemoveGroup(selectGroup);
AssetBundleCollectorSettingData.RemoveGroup(selectPackage, selectGroup);
FillGroupViewData();
}
@ -314,17 +487,7 @@ namespace YooAsset.Editor
{
var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
if (selectGroup == null)
{
_groupContainer.visible = false;
return;
}
_lastModifyGroup = selectGroup.GroupName;
_groupContainer.visible = true;
_activeRulePopupField.SetValueWithoutNotify(selectGroup.ActiveRuleName);
_groupNameTxt.SetValueWithoutNotify(selectGroup.GroupName);
_groupDescTxt.SetValueWithoutNotify(selectGroup.GroupDesc);
_groupAssetTagsTxt.SetValueWithoutNotify(selectGroup.AssetTags);
// 填充数据
_collectorScrollView.Clear();
@ -570,7 +733,8 @@ namespace YooAsset.Editor
try
{
collectAssetInfos = collector.GetAllCollectAssets(EBuildMode.DryRunBuild, group);
bool enableAdressable = AssetBundleCollectorSettingData.Setting.EnableAddressable;
collectAssetInfos = collector.GetAllCollectAssets(EBuildMode.DryRunBuild, enableAdressable, group);
}
catch (System.Exception e)
{
@ -611,7 +775,8 @@ namespace YooAsset.Editor
return;
Undo.RecordObject(AssetBundleCollectorSettingData.Setting, "YooAsset.AssetBundleCollectorWindow AddCollector");
AssetBundleCollectorSettingData.CreateCollector(selectGroup);
AssetBundleCollector collector = new AssetBundleCollector();
AssetBundleCollectorSettingData.CreateCollector(selectGroup, collector);
FillCollectorViewData();
}
private void RemoveCollectorBtn_clicked(AssetBundleCollector selectCollector)

View File

@ -5,28 +5,39 @@
<ui:Button text="导入" display-tooltip-when-elided="true" name="ImportButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
<ui:Button text="修复" display-tooltip-when-elided="true" name="FixButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
</uie:Toolbar>
<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:VisualElement>
<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="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;">
<ui:Label text="Packages" display-tooltip-when-elided="true" name="PackageTitle" style="background-color: rgb(89, 89, 89); -unity-text-align: upper-center; -unity-font-style: bold; border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px; font-size: 12px;" />
<ui:ListView focusable="true" name="PackageListView" item-height="20" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
<ui:VisualElement name="PackageAddContainer" 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="AddBtn" />
</ui:VisualElement>
</ui:VisualElement>
<ui:VisualElement name="GroupContainer" 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:Label text="Groups" display-tooltip-when-elided="true" name="GroupTitle" style="background-color: rgb(89, 89, 89); -unity-text-align: upper-center; -unity-font-style: bold; border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px; font-size: 12px;" />
<ui:TextField picking-mode="Ignore" label="Package Name" value="filler text" name="PackageName" style="flex-direction: column;" />
<ui:TextField picking-mode="Ignore" label="Package Desc" value="filler text" name="PackageDesc" style="flex-direction: column;" />
<ui:ListView focusable="true" name="GroupListView" item-height="20" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
<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="AddBtn" />
</ui:VisualElement>
</ui:VisualElement>
<ui:VisualElement name="RightContainer" style="flex-direction: column; flex-grow: 1;">
<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="Enable Addressable" name="EnableAddressable" style="width: 196px; -unity-text-align: middle-left;" />
</ui:VisualElement>
<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:VisualElement name="ActiveRuleContainer" style="height: 20px;" />
<ui:TextField picking-mode="Ignore" label="Group Name" name="GroupName" />
<ui:TextField picking-mode="Ignore" label="Group Desc" name="GroupDesc" />
<ui:TextField picking-mode="Ignore" label="Group Asset Tags" name="GroupAssetTags" />
<ui:VisualElement name="CollectorAddContainer" style="height: 20px; flex-direction: row-reverse;">
<ui:Button text="[ + ]" display-tooltip-when-elided="true" name="AddBtn" />
</ui:VisualElement>
<ui:ScrollView name="CollectorScrollView" style="flex-grow: 1;" />
<ui:VisualElement name="CollectorContainer" style="flex-grow: 1; border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px;">
<ui:Label text="Collectors" display-tooltip-when-elided="true" name="CollectorTitle" style="background-color: rgb(89, 89, 89); -unity-text-align: upper-center; -unity-font-style: bold; border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px; font-size: 12px;" />
<ui:VisualElement name="ActiveRuleContainer" style="height: 20px;" />
<ui:TextField picking-mode="Ignore" label="Group Name" name="GroupName" />
<ui:TextField picking-mode="Ignore" label="Group Desc" name="GroupDesc" />
<ui:TextField picking-mode="Ignore" label="Group Asset Tags" name="GroupAssetTags" />
<ui:VisualElement name="CollectorAddContainer" style="height: 20px; flex-direction: row-reverse;">
<ui:Button text="[ + ]" display-tooltip-when-elided="true" name="AddBtn" />
</ui:VisualElement>
<ui:ScrollView name="CollectorScrollView" style="flex-grow: 1;" />
</ui:VisualElement>
</ui:VisualElement>
</ui:UXML>

View File

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