Skip to content

Commit 06742b1

Browse files
authored
Merge pull request #73 from arimger/develop
Develop - 0.12.1
2 parents 5c9f794 + 0c62192 commit 06742b1

20 files changed

Lines changed: 341 additions & 240 deletions

Assets/Editor Toolbox/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.12.1 [12.04.2023]
2+
3+
### Changed:
4+
- Fix LabelByChild usage within lists
5+
- Possibility to foldout/in dictionaries
6+
17
## 0.12.0 [10.12.2022]
28

39
### Changed:

Assets/Editor Toolbox/Editor/Drawers/Regular/LabelByChildAttributeDrawer.cs

Lines changed: 0 additions & 111 deletions
This file was deleted.

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

Assets/Editor Toolbox/Editor/ToolboxEditorSettings.cs

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
namespace Toolbox.Editor
88
{
99
using Toolbox.Editor.Drawers;
10-
using Toolbox.Editor.Hierarchy;
1110
using Toolbox.Editor.Folders;
11+
using Toolbox.Editor.Hierarchy;
1212

1313
internal interface IToolboxGeneralSettings
1414
{ }
@@ -201,6 +201,37 @@ private void OnValidate()
201201

202202
#endregion
203203

204+
public void Reset()
205+
{
206+
ResetHierarchySettings();
207+
ResetProjectSettings();
208+
ResetInspectorSettings();
209+
}
210+
211+
public void ResetHierarchySettings()
212+
{
213+
UseToolboxHierarchy = true;
214+
RowDataTypes = Defaults.rowDataTypes;
215+
DrawHorizontalLines = true;
216+
ShowSelectionsCount = true;
217+
}
218+
219+
public void ResetProjectSettings()
220+
{
221+
UseToolboxProject = true;
222+
ResetIconRectProperties();
223+
CustomFolders = new List<FolderData>();
224+
}
225+
226+
public void ResetInspectorSettings()
227+
{
228+
UseToolboxDrawers = true;
229+
SetAllPossibleDecoratorDrawers();
230+
SetAllPossibleConditionDrawers();
231+
SetAllPossibleSelfPropertyDrawers();
232+
SetAllPossibleListPropertyDrawers();
233+
SetAllPossibleTargetTypeDrawers();
234+
}
204235

205236
public void SetAllPossibleDecoratorDrawers()
206237
{
@@ -252,7 +283,6 @@ public void SetAllPossibleTargetTypeDrawers()
252283
}
253284
}
254285

255-
256286
public void ResetIconRectProperties()
257287
{
258288
largeIconScale = Defaults.largeFolderIconScaleDefault;
@@ -331,10 +361,10 @@ public bool UseToolboxDrawers
331361
set => useToolboxDrawers = value;
332362
}
333363

334-
public bool ForceDefaultLists
335-
{
336-
get => forceDefaultLists;
337-
set => forceDefaultLists = value;
364+
public bool ForceDefaultLists
365+
{
366+
get => forceDefaultLists;
367+
set => forceDefaultLists = value;
338368
}
339369

340370
public List<SerializedType> DecoratorDrawerHandlers

Assets/Editor Toolbox/Editor/ToolboxManager.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace Toolbox.Editor
66
{
77
using Editor = UnityEditor.Editor;
88

9-
[InitializeOnLoad]
109
internal static class ToolboxManager
1110
{
1211
private const string settingsType = nameof(ToolboxEditorSettings);

Assets/Editor Toolbox/Editor/ToolboxPropertyHandler.cs

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Toolbox.Editor
99
{
10+
using Toolbox.Attributes;
1011
using Toolbox.Editor.Drawers;
1112

1213
/// <summary>
@@ -83,6 +84,12 @@ internal class ToolboxPropertyHandler
8384
/// </summary>
8485
private bool hasToolboxConditionDrawer;
8586

87+
/// <summary>
88+
/// Temporary solution to cache all attributes responsible for overriding label.
89+
/// This will be replaced with validation attributes.
90+
/// </summary>
91+
private ILabelProcessorAttribute labelProcessorAttribute;
92+
8693

8794
/// <summary>
8895
/// Constructor prepares all property-related data for custom drawing.
@@ -166,19 +173,28 @@ private void CheckIfPropertyHasPropertyDrawer(Type type)
166173

167174
private void HandleNewAttribute(PropertyAttribute attribute)
168175
{
169-
if (!isChild)
176+
//NOTE: setting tooltip and labels is valid only for parent or single properties
177+
//it's a bit ugly but, it's the only semi-acceptable way to support built-in TooltipAttribute
178+
//TODO: move these attributes to validation drawers
179+
switch (attribute)
170180
{
171-
//NOTE: setting tooltip and labels is valid only for parent or single properties
172-
//it's a bit ugly but, it's the only semi-acceptable way to support built-in TooltipAttribute
173-
switch (attribute)
174-
{
175-
case TooltipAttribute a:
176-
label.tooltip = a.tooltip;
177-
return;
178-
case NewLabelAttribute a:
179-
label.text = a.NewLabel;
180-
return;
181-
}
181+
case TooltipAttribute a:
182+
label.tooltip = a.tooltip;
183+
return;
184+
case NewLabelAttribute a:
185+
if (!isChild)
186+
{
187+
labelProcessorAttribute = a;
188+
}
189+
190+
return;
191+
case LabelByChildAttribute a:
192+
if (!isArray)
193+
{
194+
labelProcessorAttribute = a;
195+
}
196+
197+
return;
182198
}
183199

184200
var attributeType = attribute.GetType();
@@ -269,6 +285,8 @@ private bool TryAssignConditionAttribute(ToolboxConditionAttribute attribute)
269285

270286
private void DrawProperty(SerializedProperty property, GUIContent label)
271287
{
288+
ProcessLabel(property, label);
289+
272290
//get toolbox drawer for the property or draw it in the default way
273291
if (hasToolboxPropertyDrawer && (!hasBuiltInPropertyDrawer || isArray))
274292
{
@@ -360,6 +378,25 @@ private PropertyCondition Validate(SerializedProperty property)
360378
return ToolboxDrawerModule.GetConditionDrawer(conditionAttribute)?.OnGuiValidate(property, conditionAttribute) ?? PropertyCondition.Valid;
361379
}
362380

381+
//TODO: replace this method with validation attributes
382+
private void ProcessLabel(SerializedProperty property, GUIContent label)
383+
{
384+
if (labelProcessorAttribute == null)
385+
{
386+
return;
387+
}
388+
389+
switch (labelProcessorAttribute)
390+
{
391+
case NewLabelAttribute a:
392+
label.text = a.NewLabel;
393+
return;
394+
case LabelByChildAttribute a:
395+
PropertyUtility.OverrideLabelByChild(label, property, a.ChildName);
396+
return;
397+
}
398+
}
399+
363400

364401
/// <summary>
365402
/// Draw property using built-in layout system and cached <see cref="ToolboxAttributeDrawer"/>s.

0 commit comments

Comments
 (0)