Skip to content

Commit e661ef5

Browse files
committed
Possibility to fold SerializedDictionary
1 parent a35d1e7 commit e661ef5

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

Assets/Editor Toolbox/Editor/Drawers/Toolbox/TargetType/SerializedDictionaryDrawer.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,26 @@ static SerializedDictionaryDrawer()
1717
var pairsProperty = a.pairsProperty;
1818
var errorProperty = a.errorProperty;
1919

20-
var list = new ToolboxEditorList(pairsProperty, "Pair", true, true, false);
20+
var list = new ToolboxEditorList(pairsProperty, "Pair", true, true, false)
21+
{
22+
Foldable = true
23+
};
2124
list.drawHeaderCallback += (rect) =>
2225
{
2326
//cache preprocessed label to get prefab related functions
2427
var label = EditorGUI.BeginProperty(rect, null, p);
28+
2529
//create additional warning message if there is a collision
2630
if (errorProperty.boolValue)
2731
{
28-
label.image = EditorGuiUtility.GetHelpIcon(MessageType.Warning);
2932
label.text += string.Format(" [{0}]", Style.warningMessage);
33+
var warningRect = rect;
34+
warningRect.xMin = warningRect.xMax - Style.warningIconOffset;
35+
var warningIcon = new GUIContent(EditorGuiUtility.GetHelpIcon(MessageType.Warning));
36+
EditorGUI.LabelField(warningRect, warningIcon);
3037
}
31-
EditorGUI.LabelField(rect, label);
38+
39+
list.DrawStandardFoldout(rect, label);
3240
EditorGUI.EndProperty();
3341
};
3442
list.drawFooterCallback += (rect) =>
@@ -87,6 +95,7 @@ public override bool UseForChildren()
8795

8896
private static class Style
8997
{
98+
internal static readonly float warningIconOffset = 25.0f;
9099
internal static readonly string warningMessage = "keys are not unique, it will break deserialization";
91100
}
92101

0 commit comments

Comments
 (0)