Add support for copy/paste/rever values for groups in Custom Editor (eg. array editor)

This commit is contained in:
Wojtek Figat
2021-01-26 12:52:03 +01:00
parent aa2eeb8243
commit 8180877269
2 changed files with 48 additions and 12 deletions

View File

@@ -5,6 +5,7 @@ using System.Collections.Generic;
using FlaxEditor.CustomEditors.Elements;
using FlaxEditor.CustomEditors.GUI;
using FlaxEditor.GUI;
using FlaxEditor.GUI.ContextMenu;
using FlaxEngine;
using FlaxEngine.Assertions;
using FlaxEngine.GUI;
@@ -553,6 +554,8 @@ namespace FlaxEditor.CustomEditors
var group = Group(name, true);
group.Panel.Close(false);
group.Panel.TooltipText = tooltip;
group.Panel.Tag = editor;
group.Panel.MouseButtonRightClicked += OnGroupPanelMouseButtonRightClicked;
return group.Object(values, editor);
}
@@ -560,6 +563,23 @@ namespace FlaxEditor.CustomEditors
return property.Object(values, editor);
}
private void OnGroupPanelMouseButtonRightClicked(DropPanel groupPanel, Vector2 location)
{
var linkedEditor = (CustomEditor)groupPanel.Tag;
var menu = new ContextMenu();
var revertToPrefab = menu.AddButton("Revert to Prefab", linkedEditor.RevertToReferenceValue);
revertToPrefab.Enabled = linkedEditor.CanRevertReferenceValue;
var resetToDefault = menu.AddButton("Reset to default", linkedEditor.RevertToDefaultValue);
resetToDefault.Enabled = linkedEditor.CanRevertDefaultValue;
menu.AddSeparator();
menu.AddButton("Copy", linkedEditor.Copy);
var paste = menu.AddButton("Paste", linkedEditor.Paste);
paste.Enabled = linkedEditor.CanPaste;
menu.Show(groupPanel, location);
}
/// <summary>
/// Adds object property editor. Selects proper <see cref="CustomEditor"/> based on overrides.
/// </summary>