diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollector.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollector.cs
index 79543c5..b2477cb 100644
--- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollector.cs
+++ b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollector.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
+using UnityEngine;
namespace YooAsset.Editor
{
@@ -14,6 +15,11 @@ namespace YooAsset.Editor
///
public string CollectPath = string.Empty;
+ ///
+ /// 收集器的GUID
+ ///
+ public string CollectorGUID = string.Empty;
+
///
/// 收集器类型
///
@@ -68,7 +74,8 @@ namespace YooAsset.Editor
///
public void CheckConfigError()
{
- if (AssetDatabase.LoadAssetAtPath(CollectPath) == null)
+ string assetGUID = AssetDatabase.AssetPathToGUID(CollectPath);
+ if (string.IsNullOrEmpty(assetGUID))
throw new Exception($"Invalid collect path : {CollectPath}");
if (CollectorType == ECollectorType.None)
@@ -84,6 +91,44 @@ namespace YooAsset.Editor
throw new Exception($"Invalid {nameof(IAddressRule)} class type : {AddressRuleName} in collector : {CollectPath}");
}
+ ///
+ /// 修复配置错误
+ ///
+ public bool FixConfigError()
+ {
+ bool isFixed = false;
+
+ if (string.IsNullOrEmpty(CollectorGUID) == false)
+ {
+ string convertAssetPath = AssetDatabase.GUIDToAssetPath(CollectorGUID);
+ if (string.IsNullOrEmpty(convertAssetPath))
+ {
+ Debug.LogWarning($"Collector GUID {CollectorGUID} is invalid and has been auto removed !");
+ CollectorGUID = string.Empty;
+ isFixed = true;
+ }
+ else
+ {
+ if (CollectPath != convertAssetPath)
+ {
+ CollectPath = convertAssetPath;
+ isFixed = true;
+ Debug.LogWarning($"Fix collect path : {CollectPath} -> {convertAssetPath}");
+ }
+ }
+ }
+
+ /*
+ string convertGUID = AssetDatabase.AssetPathToGUID(CollectPath);
+ if(string.IsNullOrEmpty(convertGUID) == false)
+ {
+ CollectorGUID = convertGUID;
+ }
+ */
+
+ return isFixed;
+ }
+
///
/// 获取打包收集的资源文件
///
diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorConfig.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorConfig.cs
index 58b9159..4768305 100644
--- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorConfig.cs
+++ b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorConfig.cs
@@ -20,12 +20,13 @@ namespace YooAsset.Editor
public const string XmlGroupDesc = "GroupDesc";
public const string XmlCollector = "Collector";
public const string XmlCollectPath = "CollectPath";
+ public const string XmlCollectorGUID = "CollectGUID";
public const string XmlCollectorType = "CollectType";
public const string XmlAddressRule = "AddressRule";
public const string XmlPackRule = "PackRule";
public const string XmlFilterRule = "FilterRule";
public const string XmlAssetTags = "AssetTags";
-
+
///
/// 导入XML配置表
///
@@ -44,7 +45,7 @@ namespace YooAsset.Editor
// 读取配置版本
string configVersion = root.GetAttribute(XmlVersion);
- if(configVersion != ConfigVersion)
+ if (configVersion != ConfigVersion)
{
throw new Exception($"The config version is invalid : {configVersion}");
}
@@ -97,13 +98,18 @@ namespace YooAsset.Editor
if (collectorElement.HasAttribute(XmlAssetTags) == false)
throw new Exception($"Not found attribute {XmlAssetTags} in {XmlCollector}");
+ string collectorGUID = string.Empty;
+ if (collectorElement.HasAttribute(XmlCollectorGUID))
+ collectorGUID = collectorElement.GetAttribute(XmlCollectorGUID);
+
AssetBundleCollector collector = new AssetBundleCollector();
collector.CollectPath = collectorElement.GetAttribute(XmlCollectPath);
+ collector.CollectorGUID = collectorGUID;
collector.CollectorType = StringUtility.NameToEnum(collectorElement.GetAttribute(XmlCollectorType));
collector.AddressRuleName = collectorElement.GetAttribute(XmlAddressRule);
collector.PackRuleName = collectorElement.GetAttribute(XmlPackRule);
collector.FilterRuleName = collectorElement.GetAttribute(XmlFilterRule);
- collector.AssetTags = collectorElement.GetAttribute(XmlAssetTags); ;
+ collector.AssetTags = collectorElement.GetAttribute(XmlAssetTags);
group.Collectors.Add(collector);
}
}
@@ -155,6 +161,7 @@ namespace YooAsset.Editor
{
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);
diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSetting.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSetting.cs
index 818fc1f..0e558d0 100644
--- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSetting.cs
+++ b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSetting.cs
@@ -30,6 +30,26 @@ namespace YooAsset.Editor
}
}
+ ///
+ /// 修复配置错误
+ ///
+ public bool FixConfigError()
+ {
+ bool result = false;
+ foreach (var group in Groups)
+ {
+ foreach (var collector in group.Collectors)
+ {
+ bool isFixed = collector.FixConfigError();
+ if (isFixed)
+ {
+ result = true;
+ }
+ }
+ }
+ return result;
+ }
+
///
/// 获取所有的资源标签
///
diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs
index d063390..45862bc 100644
--- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs
+++ b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs
@@ -232,7 +232,7 @@ namespace YooAsset.Editor
}
///
- /// 存储文件
+ /// 存储配置文件
///
public static void SaveFile()
{
@@ -245,6 +245,18 @@ namespace YooAsset.Editor
}
}
+ ///
+ /// 修复配置文件
+ ///
+ public static void FixFile()
+ {
+ bool isFixed = Setting.FixConfigError();
+ if (isFixed)
+ {
+ IsDirty = true;
+ }
+ }
+
///
/// 清空所有数据
///
@@ -360,10 +372,9 @@ namespace YooAsset.Editor
}
// 资源收集器编辑相关
- public static void CreateCollector(AssetBundleCollectorGroup group, string collectPath)
+ public static void CreateCollector(AssetBundleCollectorGroup group)
{
AssetBundleCollector collector = new AssetBundleCollector();
- collector.CollectPath = collectPath;
group.Collectors.Add(collector);
IsDirty = true;
}
diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs
index 088e824..0fe41e7 100644
--- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs
+++ b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs
@@ -62,6 +62,10 @@ namespace YooAsset.Editor
visualAsset.CloneTree(root);
+ // 配置修复按钮
+ var fixBtn = root.Q