Add cross button to unset abstract class or interface object value

This commit is contained in:
2026-07-22 11:30:49 +02:00
parent d92f2a0437
commit 55a756532b
2 changed files with 8 additions and 2 deletions
@@ -707,10 +707,10 @@ namespace FlaxEditor.CustomEditors.Editors
if (!HasDifferentTypes)
{
var value = Values[0];
var type = Values.Type;
if (value == null)
{
// Check if it's an object type that can be created in editor
var type = Values.Type;
if (type != ScriptMemberInfo.Null)
{
ScriptType[] types = null;
@@ -754,6 +754,12 @@ namespace FlaxEditor.CustomEditors.Editors
layout.Label("<null>");
return;
}
if (!type.IsArray && !type.IsStructure && !type.IsScriptingObject && (type.IsAbstract || type.IsInterface) && value.GetType() != type.Type && layout is GroupElement group)
{
// Add button to unset the value to null (eg. to edit it to different type)
var button = group.AddHeaderButton("Reset value to null", 0, FlaxEngine.GUI.Style.Current.Cross);
button.Clicked += (_, _) => SetValue(null);
}
items = GetItemsForType(TypeUtils.GetObjectType(value));
}
@@ -55,7 +55,7 @@ namespace FlaxEditor.CustomEditors.Elements
const float padding = 2.0f;
var settingsButtonSize = Panel.HeaderHeight;
Panel.HeaderTextMargin = Panel.HeaderTextMargin with { Right = settingsButtonSize + Utilities.Constants.UIMargin };
; return new Image
return new Image
{
TooltipText = tooltipText,
AutoFocus = true,