The collector window supports undo operations

资源收集界面支持撤销操作
pull/13/head
hevinci 2022-05-21 23:41:58 +08:00
parent e9841a65c6
commit d43d30f72f
1 changed files with 21 additions and 3 deletions

View File

@ -31,6 +31,8 @@ namespace YooAsset.Editor
private TextField _groupDescTxt; private TextField _groupDescTxt;
private TextField _groupAssetTagsTxt; private TextField _groupAssetTagsTxt;
private VisualElement _groupContainer; private VisualElement _groupContainer;
private string _lastModifyGroup = string.Empty;
public void CreateGUI() public void CreateGUI()
{ {
@ -164,6 +166,9 @@ namespace YooAsset.Editor
} }
public void OnDestroy() public void OnDestroy()
{ {
// 注意:清空所有撤销操作
Undo.ClearAll();
if (AssetBundleCollectorSettingData.IsDirty) if (AssetBundleCollectorSettingData.IsDirty)
AssetBundleCollectorSettingData.SaveFile(); AssetBundleCollectorSettingData.SaveFile();
} }
@ -203,6 +208,16 @@ namespace YooAsset.Editor
_groupListView.ClearSelection(); _groupListView.ClearSelection();
_groupListView.itemsSource = AssetBundleCollectorSettingData.Setting.Groups; _groupListView.itemsSource = AssetBundleCollectorSettingData.Setting.Groups;
_groupListView.Rebuild(); _groupListView.Rebuild();
for (int index = 0; index < AssetBundleCollectorSettingData.Setting.Groups.Count; index++)
{
var group = AssetBundleCollectorSettingData.Setting.Groups[index];
if (group.GroupName == _lastModifyGroup)
{
_groupListView.selectedIndex = index;
break;
}
}
} }
private VisualElement MakeGroupListViewItem() private VisualElement MakeGroupListViewItem()
{ {
@ -236,7 +251,7 @@ namespace YooAsset.Editor
} }
private void AddGroupBtn_clicked() private void AddGroupBtn_clicked()
{ {
Undo.RecordObject(AssetBundleCollectorSettingData.Setting, "YooAsset AddGroup"); Undo.RecordObject(AssetBundleCollectorSettingData.Setting, "YooAsset.AssetBundleCollectorWindow AddGroup");
AssetBundleCollectorSettingData.CreateGroup("Default Group"); AssetBundleCollectorSettingData.CreateGroup("Default Group");
FillGroupViewData(); FillGroupViewData();
} }
@ -246,8 +261,7 @@ namespace YooAsset.Editor
if (selectGroup == null) if (selectGroup == null)
return; return;
Undo.RecordObject(AssetBundleCollectorSettingData.Setting, "YooAsset RemoveGroup"); Undo.RecordObject(AssetBundleCollectorSettingData.Setting, "YooAsset.AssetBundleCollectorWindow RemoveGroup");
AssetBundleCollectorSettingData.RemoveGroup(selectGroup); AssetBundleCollectorSettingData.RemoveGroup(selectGroup);
FillGroupViewData(); FillGroupViewData();
} }
@ -262,6 +276,7 @@ namespace YooAsset.Editor
return; return;
} }
_lastModifyGroup = selectGroup.GroupName;
_groupContainer.visible = true; _groupContainer.visible = true;
_groupNameTxt.SetValueWithoutNotify(selectGroup.GroupName); _groupNameTxt.SetValueWithoutNotify(selectGroup.GroupName);
_groupDescTxt.SetValueWithoutNotify(selectGroup.GroupDesc); _groupDescTxt.SetValueWithoutNotify(selectGroup.GroupDesc);
@ -550,6 +565,7 @@ namespace YooAsset.Editor
if (selectGroup == null) if (selectGroup == null)
return; return;
Undo.RecordObject(AssetBundleCollectorSettingData.Setting, "YooAsset.AssetBundleCollectorWindow AddCollector");
AssetBundleCollectorSettingData.CreateCollector(selectGroup, string.Empty); AssetBundleCollectorSettingData.CreateCollector(selectGroup, string.Empty);
FillCollectorViewData(); FillCollectorViewData();
} }
@ -560,6 +576,8 @@ namespace YooAsset.Editor
return; return;
if (selectCollector == null) if (selectCollector == null)
return; return;
Undo.RecordObject(AssetBundleCollectorSettingData.Setting, "YooAsset.AssetBundleCollectorWindow RemoveCollector");
AssetBundleCollectorSettingData.RemoveCollector(selectGroup, selectCollector); AssetBundleCollectorSettingData.RemoveCollector(selectGroup, selectCollector);
FillCollectorViewData(); FillCollectorViewData();
} }