Add support for displaying and reverting array values to prefab value in properties panel

#1548
This commit is contained in:
Wojtek Figat
2023-12-14 13:57:16 +01:00
parent 190bafea28
commit fe1a655654
2 changed files with 63 additions and 45 deletions

View File

@@ -87,6 +87,7 @@ namespace FlaxEditor.CustomEditors.Editors
protected bool NotNullItems;
private IntegerValueElement _size;
private PropertyNameLabel _sizeLabel;
private Color _background;
private int _elementsCount;
private bool _readOnly;
@@ -109,6 +110,9 @@ namespace FlaxEditor.CustomEditors.Editors
}
}
/// <inheritdoc />
public override bool RevertValueWithChildren => false; // Always revert value for a whole collection
/// <inheritdoc />
public override void Initialize(LayoutElementsContainer layout)
{
@@ -174,7 +178,9 @@ namespace FlaxEditor.CustomEditors.Editors
}
else
{
_size = dragArea.IntegerValue("Size");
var sizeProperty = dragArea.AddPropertyItem("Size");
_sizeLabel = sizeProperty.Labels.Last();
_size = sizeProperty.IntegerValue();
_size.IntValue.MinValue = 0;
_size.IntValue.MaxValue = ushort.MaxValue;
_size.IntValue.Value = size;
@@ -274,6 +280,15 @@ namespace FlaxEditor.CustomEditors.Editors
}
}
/// <inheritdoc />
protected override void Deinitialize()
{
_size = null;
_sizeLabel = null;
base.Deinitialize();
}
/// <summary>
/// Rebuilds the parent layout if its collection.
/// </summary>
@@ -296,7 +311,6 @@ namespace FlaxEditor.CustomEditors.Editors
{
if (IsSetBlocked)
return;
Resize(_size.IntValue.Value);
}
@@ -311,11 +325,9 @@ namespace FlaxEditor.CustomEditors.Editors
return;
var cloned = CloneValues();
var tmp = cloned[dstIndex];
cloned[dstIndex] = cloned[srcIndex];
cloned[srcIndex] = tmp;
SetValue(cloned);
}
@@ -371,6 +383,17 @@ namespace FlaxEditor.CustomEditors.Editors
if (HasDifferentValues || HasDifferentTypes)
return;
// Update reference/default value indicator
if (_sizeLabel != null)
{
var color = Color.Transparent;
if (Values.HasReferenceValue && Values.ReferenceValue is IList referenceValue && referenceValue.Count != Count)
color = FlaxEngine.GUI.Style.Current.BackgroundSelected;
else if (Values.HasDefaultValue && Values.DefaultValue is IList defaultValue && defaultValue.Count != Count)
color = Color.Yellow * 0.8f;
_sizeLabel.HighlightStripColor = color;
}
// Check if collection has been resized (by UI or from external source)
if (Count != _elementsCount)
{