Update AssetBundleGrouper

优化了资源分组配置保存策略
pull/4/head
hevinci 2022-04-09 12:02:02 +08:00
parent f38d663e9d
commit d2d6d2ad14
2 changed files with 31 additions and 17 deletions

View File

@ -14,6 +14,11 @@ namespace YooAsset.Editor
private static readonly Dictionary<string, System.Type> _cacheFilterRuleTypes = new Dictionary<string, System.Type>();
private static readonly Dictionary<string, IFilterRule> _cacheFilterRuleInstance = new Dictionary<string, IFilterRule>();
/// <summary>
/// 配置数据是否被修改
/// </summary>
public static bool IsDirty { private set; get; } = false;
private static AssetBundleGrouperSetting _setting = null;
public static AssetBundleGrouperSetting Setting
@ -147,8 +152,10 @@ namespace YooAsset.Editor
{
if (Setting != null)
{
IsDirty = false;
EditorUtility.SetDirty(Setting);
AssetDatabase.SaveAssets();
Debug.Log($"{nameof(AssetBundleGrouperSetting)}.asset is saved!");
}
}
@ -202,42 +209,42 @@ namespace YooAsset.Editor
// 着色器编辑相关
public static void ModifyShader(bool isCollectAllShaders, string shadersBundleName)
{
if (string.IsNullOrEmpty(shadersBundleName))
return;
Setting.AutoCollectShaders = isCollectAllShaders;
Setting.ShadersBundleName = shadersBundleName;
SaveFile();
IsDirty = true;
}
// 资源分组编辑相关
public static void CreateGrouper(string grouperName, string grouperDesc, string assetTags, bool saveFile = true)
public static void CreateGrouper(string grouperName, string grouperDesc, string assetTags)
{
AssetBundleGrouper grouper = new AssetBundleGrouper();
grouper.GrouperName = grouperName;
grouper.GrouperDesc = grouperDesc;
grouper.AssetTags = assetTags;
Setting.Groupers.Add(grouper);
if (saveFile)
SaveFile();
IsDirty = true;
}
public static void RemoveGrouper(AssetBundleGrouper grouper)
{
if (Setting.Groupers.Remove(grouper))
{
SaveFile();
IsDirty = true;
}
else
{
Debug.LogWarning($"Failed remove grouper : {grouper.GrouperName}");
}
}
public static void ModifyGrouper(AssetBundleGrouper grouper)
{
if (grouper != null)
{
SaveFile();
IsDirty = true;
}
}
// 资源收集器编辑相关
public static void CreateCollector(AssetBundleGrouper grouper, string collectPath, string packRuleName, string filterRuleName, bool notWriteToAssetList, bool saveFile = true)
public static void CreateCollector(AssetBundleGrouper grouper, string collectPath, string packRuleName, string filterRuleName, bool notWriteToAssetList)
{
AssetBundleCollector collector = new AssetBundleCollector();
collector.CollectPath = collectPath;
@ -245,22 +252,24 @@ namespace YooAsset.Editor
collector.FilterRuleName = filterRuleName;
collector.NotWriteToAssetList = notWriteToAssetList;
grouper.Collectors.Add(collector);
if (saveFile)
SaveFile();
IsDirty = true;
}
public static void RemoveCollector(AssetBundleGrouper grouper, AssetBundleCollector collector)
{
if (grouper.Collectors.Remove(collector))
{
SaveFile();
IsDirty = true;
}
else
{
Debug.LogWarning($"Failed remove collector : {collector.CollectPath}");
}
}
public static void ModifyCollector(AssetBundleGrouper grouper, AssetBundleCollector collector)
{
if (grouper != null && collector != null)
{
SaveFile();
IsDirty = true;
}
}
}

View File

@ -152,6 +152,11 @@ namespace YooAsset.Editor
Debug.LogError(e.ToString());
}
}
public void OnDestroy()
{
if (AssetBundleGrouperSettingData.IsDirty)
AssetBundleGrouperSettingData.SaveFile();
}
// 刷新窗体
private void RefreshWindow()
@ -222,7 +227,7 @@ namespace YooAsset.Editor
}
private void AddGrouperBtn_clicked()
{
AssetBundleGrouperSettingData.CreateGrouper("Default Grouper", string.Empty, string.Empty, true);
AssetBundleGrouperSettingData.CreateGrouper("Default Grouper", string.Empty, string.Empty);
FillGrouperViewData();
}
private void RemoveGrouperBtn_clicked()