Skip to content

Commit c7d4985

Browse files
committed
Possibility to ignore certain properties directly in the OnGUI callback
1 parent 9d3037b commit c7d4985

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

Assets/Editor Toolbox/Editor/ToolboxEditor.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23

34
using UnityEditor;
45

@@ -14,6 +15,9 @@ namespace Toolbox.Editor
1415
[CanEditMultipleObjects]
1516
public class ToolboxEditor : Editor
1617
{
18+
private readonly HashSet<string> propertiesToIgnore = new HashSet<string>();
19+
20+
1721
/// <summary>
1822
/// Inspector GUI re-draw call.
1923
/// </summary>
@@ -37,13 +41,18 @@ public override sealed void OnInspectorGUI()
3741
}
3842
}
3943

40-
4144
/// <summary>
4245
/// Handles property display process using custom <see cref="Drawers.ToolboxDrawer"/>.
4346
/// </summary>
4447
/// <param name="property">Property to display.</param>
4548
public virtual void DrawCustomProperty(SerializedProperty property)
4649
{
50+
var propertyPath = property.propertyPath;
51+
if (propertiesToIgnore.Contains(propertyPath))
52+
{
53+
return;
54+
}
55+
4756
ToolboxEditorGui.DrawToolboxProperty(property);
4857
}
4958

@@ -85,6 +94,22 @@ public virtual void DrawCustomInspector()
8594
DrawDefaultInspector();
8695
}
8796

97+
/// <summary>
98+
/// Forces provided <see cref="SerializedProperty"/> to be ignored in the drawing process.
99+
/// </summary>
100+
public void IgnoreProperty(SerializedProperty property)
101+
{
102+
IgnoreProperty(property.propertyPath);
103+
}
104+
105+
/// <summary>
106+
/// Forces associated <see cref="SerializedProperty"/> to be ignored in the drawing process.
107+
/// </summary>
108+
public void IgnoreProperty(string propertyPath)
109+
{
110+
propertiesToIgnore.Add(propertyPath);
111+
}
112+
88113

89114
public static event Action<Editor> OnBeginToolboxEditor;
90115
public static event Action<Editor> OnBreakToolboxEditor;

0 commit comments

Comments
 (0)