Add support for multi-control editing

#1897
This commit is contained in:
Wojtek Figat
2024-12-09 18:47:32 +01:00
parent 6a082e9dd7
commit eb5dfcd6bf

View File

@@ -407,20 +407,13 @@ namespace FlaxEditor.CustomEditors.Dedicated
/// <seealso cref="FlaxEditor.CustomEditors.Editors.GenericEditor" /> /// <seealso cref="FlaxEditor.CustomEditors.Editors.GenericEditor" />
public class UIControlControlEditor : GenericEditor public class UIControlControlEditor : GenericEditor
{ {
private Type _cachedType; private ScriptType[] _valueTypes;
private bool _anchorDropDownClosed = true; private bool _anchorDropDownClosed = true;
private Button _pivotRelativeButton; private Button _pivotRelativeButton;
/// <inheritdoc /> /// <inheritdoc />
public override void Initialize(LayoutElementsContainer layout) public override void Initialize(LayoutElementsContainer layout)
{ {
_cachedType = null;
if (HasDifferentTypes)
{
// TODO: support stable editing multiple different control types (via generic way or for transform-only)
return;
}
// Set control type button // Set control type button
var space = layout.Space(20); var space = layout.Space(20);
var buttonText = "Set Type"; var buttonText = "Set Type";
@@ -445,12 +438,12 @@ namespace FlaxEditor.CustomEditors.Dedicated
} }
// Add control type helper label // Add control type helper label
if (!Values.HasDifferentTypes)
{ {
var type = Values[0].GetType();
_cachedType = type;
var label = layout.AddPropertyItem("Type", "The type of the created control."); var label = layout.AddPropertyItem("Type", "The type of the created control.");
label.Label(type.FullName); label.Label(Values[0].GetType().FullName);
} }
_valueTypes = Values.ValuesTypes;
// Show control properties // Show control properties
base.Initialize(layout); base.Initialize(layout);
@@ -719,12 +712,11 @@ namespace FlaxEditor.CustomEditors.Dedicated
/// <inheritdoc /> /// <inheritdoc />
public override void Refresh() public override void Refresh()
{
if (_cachedType != null)
{ {
// Automatic layout rebuild if control type gets changed // Automatic layout rebuild if control type gets changed
var type = Values.HasNull ? null : Values[0].GetType(); if (_valueTypes != null &&
if (type != _cachedType) !Values.HasNull &&
!Utils.ArraysEqual(_valueTypes, Values.ValuesTypes))
{ {
RebuildLayout(); RebuildLayout();
return; return;
@@ -736,7 +728,6 @@ namespace FlaxEditor.CustomEditors.Dedicated
{ {
RebuildLayout(); RebuildLayout();
} }
}
base.Refresh(); base.Refresh();
} }