Add ListDrawerSettings

This commit is contained in:
VladV 2022-01-21 18:46:53 +03:00
parent e730c49e40
commit 96025fbb61
3 changed files with 29 additions and 4 deletions

View File

@ -28,16 +28,23 @@ namespace TriInspector.Elements
public TriListElement(TriProperty property)
{
property.TryGetAttribute(out ListDrawerSettings settings);
_property = property;
_reorderableListGui = new ReorderableList(null, _property.ArrayElementType)
{
draggable = false,
displayAdd = true,
displayRemove = true,
draggable = settings?.Draggable ?? true,
displayAdd = settings == null || !settings.HideAddButton,
displayRemove = settings == null || !settings.HideRemoveButton,
drawHeaderCallback = DrawHeaderCallback,
elementHeightCallback = ElementHeightCallback,
drawElementCallback = DrawElementCallback,
};
if (!_reorderableListGui.displayAdd && !_reorderableListGui.displayRemove)
{
_reorderableListGui.footerHeight = 0f;
}
}
public override bool Update()
@ -166,7 +173,8 @@ namespace TriInspector.Elements
};
TriEditorGUI.Foldout(labelRect, _property);
GUI.Label(arraySizeRect, $"{_reorderableListGui.count} items", Styles.ItemsCount);
var label = _reorderableListGui.count == 0 ? "Empty" : $"{_reorderableListGui.count} items";
GUI.Label(arraySizeRect, label, Styles.ItemsCount);
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Diagnostics;
namespace TriInspector
{
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
[Conditional("UNITY_EDITOR")]
public sealed class ListDrawerSettings : Attribute
{
public bool Draggable { get; set; } = true;
public bool HideAddButton { get; set; }
public bool HideRemoveButton { get; set; }
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d58dcfa9a4df4af09d44c31a6f74ab26
timeCreated: 1642779136