Skip to content

Commit a9e3698

Browse files
committed
Minor refactor changes
1 parent deb3358 commit a9e3698

4 files changed

Lines changed: 25 additions & 16 deletions

File tree

Assets/Editor Toolbox/Editor/IToolboxEditorDrawer.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@ namespace Toolbox.Editor
44
{
55
public interface IToolboxEditorDrawer
66
{
7-
/// <summary>
8-
/// Draws each available property using internally <see cref="Drawers.ToolboxDrawer"/>s.
9-
/// </summary>
107
void DrawEditor(SerializedObject serializedObject);
118
/// <summary>
129
/// Draws <see cref="SerializedProperty"/>/ies in the default (native) way.
1310
/// </summary>
1411
/// <param name="serializedObject"></param>
1512
void DrawDefaultEditor(SerializedObject serializedObject);
1613
/// <summary>
17-
/// TODO
14+
/// Draws each available property using internally <see cref="Drawers.ToolboxDrawer"/>s.
1815
/// </summary>
1916
/// <param name="serializedObject"></param>
2017
void DrawToolboxEditor(SerializedObject serializedObject);
@@ -26,5 +23,7 @@ public interface IToolboxEditorDrawer
2623
/// Forces provided <see cref="SerializedProperty"/> to be ignored in the drawing process.
2724
/// </summary>
2825
void IgnoreProperty(string propertyPath);
26+
bool IsPropertyIgnored(SerializedProperty property);
27+
bool IsPropertyIgnored(string propertyPath);
2928
}
3029
}

Assets/Editor Toolbox/Editor/ToolboxEditor.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ public sealed override void OnInspectorGUI()
2222
ToolboxEditorHandler.HandleToolboxEditor(this);
2323
}
2424

25-
//TODO: how to handle this method, currently unused
2625
/// <inheritdoc />
26+
[Obsolete("To draw properties in a different way override the Drawer property.")]
2727
public virtual void DrawCustomProperty(SerializedProperty property)
28-
{
29-
//Drawer.DrawProperty(property);
30-
}
28+
{ }
3129

3230
/// <inheritdoc />
3331
public virtual void DrawCustomInspector()
@@ -49,7 +47,7 @@ public void IgnoreProperty(string propertyPath)
4947

5048

5149
Editor IToolboxEditor.ContextEditor => this;
52-
public IToolboxEditorDrawer Drawer { get; } = new ToolboxEditorDrawer();
50+
public virtual IToolboxEditorDrawer Drawer { get; } = new ToolboxEditorDrawer();
5351

5452
#pragma warning disable 0067
5553
[Obsolete("ToolboxEditorHandler.OnBeginToolboxEditor")]

Assets/Editor Toolbox/Editor/ToolboxEditorDrawer.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,23 @@
55

66
namespace Toolbox.Editor
77
{
8+
/// <summary>
9+
/// Default drawer responsible for drawing <see cref="UnityEditor.Editor"/>s.
10+
/// This helper class that can be used across many Toolbox-based editors that cannot share the same base class.
11+
/// </summary>
812
public class ToolboxEditorDrawer : IToolboxEditorDrawer
913
{
1014
private readonly HashSet<string> propertiesToIgnore = new HashSet<string>();
11-
//TODO:
1215
private readonly Action<SerializedProperty> toolboxDrawingAction;
1316
private readonly Action<SerializedProperty> defaultDrawingAction;
1417

15-
public ToolboxEditorDrawer()
18+
public ToolboxEditorDrawer() : this(ToolboxEditorGui.DrawToolboxProperty, ToolboxEditorGui.DrawNativeProperty)
19+
{ }
20+
21+
public ToolboxEditorDrawer(Action<SerializedProperty> toolboxDrawingAction, Action<SerializedProperty> defaultDrawingAction)
1622
{
17-
toolboxDrawingAction = ToolboxEditorGui.DrawToolboxProperty;
18-
defaultDrawingAction = ToolboxEditorGui.DrawNativeProperty;
23+
this.toolboxDrawingAction = toolboxDrawingAction;
24+
this.defaultDrawingAction = defaultDrawingAction;
1925
}
2026

2127
private void DrawProperty(SerializedProperty property, Action<SerializedProperty> drawingAction)
@@ -67,13 +73,13 @@ public void DrawEditor(SerializedObject serializedObject, Action<SerializedPrope
6773
/// <inheritdoc />
6874
public void DrawToolboxEditor(SerializedObject serializedObject)
6975
{
70-
DrawEditor(serializedObject, ToolboxEditorGui.DrawToolboxProperty);
76+
DrawEditor(serializedObject, toolboxDrawingAction);
7177
}
7278

7379
/// <inheritdoc />
7480
public void DrawDefaultEditor(SerializedObject serializedObject)
7581
{
76-
DrawEditor(serializedObject, ToolboxEditorGui.DrawNativeProperty);
82+
DrawEditor(serializedObject, defaultDrawingAction);
7783
}
7884

7985
/// <inheritdoc />
@@ -88,6 +94,12 @@ public void IgnoreProperty(string propertyPath)
8894
propertiesToIgnore.Add(propertyPath);
8995
}
9096

97+
/// <inheritdoc />
98+
public bool IsPropertyIgnored(SerializedProperty property)
99+
{
100+
return IsPropertyIgnored(property.propertyPath);
101+
}
102+
91103
/// <inheritdoc />
92104
public bool IsPropertyIgnored(string propertyPath)
93105
{

Assets/Editor Toolbox/Editor/ToolboxEditorGui.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ public static void DrawNativeProperty(SerializedProperty property)
546546
/// </summary>
547547
public static void DrawNativeProperty(SerializedProperty property, GUIContent label)
548548
{
549-
EditorGUILayout.PropertyField(property, label, property.isExpanded);
549+
EditorGUILayout.PropertyField(property, label);
550550
}
551551

552552
/// <summary>

0 commit comments

Comments
 (0)