Skip to content

Commit 394101c

Browse files
lejeanfclaude
andcommitted
feat: expose the validation banner for custom editors (1.2.2)
ValidationInspectorBanner is a [CustomEditor(typeof(MonoBehaviour), true)] fallback, so any component with its own CustomEditor silently lost the orange "needs setup" banner - it kept the hierarchy dot, field tint and console log, but the banner itself was unreachable private code. Move the drawing into ValidationUi.DrawIssuesBanner(Component) so a custom editor can call it in one line, and reduce ValidationInspectorBanner to a delegation. No behaviour change for components using the default inspector. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 5be3f9c commit 394101c

3 files changed

Lines changed: 47 additions & 40 deletions

File tree

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
namespace jeanf.validationTools
22
{
33
#if UNITY_EDITOR
4-
using System.Collections.Generic;
54
using UnityEditor;
65
using UnityEngine;
76

@@ -11,53 +10,21 @@ namespace jeanf.validationTools
1110
/// title bar — "⚠ ComponentName needs setup" plus the issue list — then the
1211
/// normal inspector (where [Validation] fields are already tinted orange by
1312
/// ValidationDrawer). Valid components render exactly like the default
14-
/// inspector. Components with their own [CustomEditor] keep it (a more
15-
/// specific editor always wins over this fallback) — they still get the
16-
/// hierarchy dot, field tint and console log, just not the banner.
13+
/// inspector. Components with their own [CustomEditor] replace this fallback
14+
/// (a more specific editor always wins) — they still get the hierarchy dot,
15+
/// field tint and console log, and can restore the banner by calling
16+
/// ValidationUi.DrawIssuesBanner themselves.
1717
/// (Unity has no public API to recolor the title bar itself, so the banner
1818
/// under it is how the component gets its orange title.)
1919
/// </summary>
2020
[CustomEditor(typeof(MonoBehaviour), true), CanEditMultipleObjects]
2121
public class ValidationInspectorBanner : Editor
2222
{
23-
private static readonly List<ValidationIssue> Issues = new List<ValidationIssue>();
24-
2523
public override void OnInspectorGUI()
2624
{
27-
var component = target as Component;
28-
if (component != null)
29-
{
30-
Issues.Clear();
31-
ValidationScanner.GetIssues(component, Issues);
32-
if (Issues.Count > 0) DrawBanner(component);
33-
}
34-
25+
ValidationUi.DrawIssuesBanner(target as Component);
3526
DrawDefaultInspector();
3627
}
37-
38-
private static void DrawBanner(Component component)
39-
{
40-
var title = $"⚠ {component.GetType().Name} needs setup";
41-
var lineHeight = EditorGUIUtility.singleLineHeight;
42-
var height = lineHeight + 6f + Issues.Count * lineHeight;
43-
44-
var rect = GUILayoutUtility.GetRect(0f, height, GUILayout.ExpandWidth(true));
45-
EditorGUI.DrawRect(rect, ValidationUi.OrangeWash);
46-
// Solid orange edge on the left, like Unity's own message stripes.
47-
EditorGUI.DrawRect(new Rect(rect.x, rect.y, 3f, rect.height), ValidationUi.Orange);
48-
49-
var line = new Rect(rect.x + 8f, rect.y + 3f, rect.width - 12f, lineHeight);
50-
EditorGUI.LabelField(line, title, ValidationUi.OrangeBoldLabel);
51-
52-
foreach (var issue in Issues)
53-
{
54-
line.y += lineHeight;
55-
var text = string.IsNullOrEmpty(issue.FieldName) ? issue.Message : $"• {issue.FieldName}: {issue.Message}";
56-
EditorGUI.LabelField(line, text, ValidationUi.OrangeLabel);
57-
}
58-
59-
EditorGUILayout.Space(2f);
60-
}
6128
}
6229
#endif
6330
}

Runtime/ValidationTools/ValidationUi.cs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
namespace jeanf.validationTools
22
{
33
#if UNITY_EDITOR
4+
using System.Collections.Generic;
5+
using UnityEditor;
46
using UnityEngine;
57

68
/// <summary>Shared colors/styles so every validation surface speaks the same orange.</summary>
@@ -33,13 +35,51 @@ public static GUIStyle OrangeBoldLabel
3335
{
3436
if (_orangeBoldLabel == null)
3537
{
36-
_orangeBoldLabel = new GUIStyle(UnityEditor.EditorStyles.boldLabel);
38+
_orangeBoldLabel = new GUIStyle(EditorStyles.boldLabel);
3739
_orangeBoldLabel.normal.textColor = Orange;
3840
_orangeBoldLabel.hover.textColor = Orange;
3941
}
4042
return _orangeBoldLabel;
4143
}
4244
}
45+
46+
private static readonly List<ValidationIssue> Issues = new List<ValidationIssue>();
47+
48+
/// <summary>
49+
/// Draws the orange "needs setup" banner for a component — title bar stripe plus the
50+
/// issue list — or nothing at all when the component is clean. ValidationInspectorBanner
51+
/// calls this for components using the default inspector; components with their own
52+
/// [CustomEditor] call it themselves so they keep the same banner instead of losing it.
53+
/// </summary>
54+
public static void DrawIssuesBanner(Component component)
55+
{
56+
if (component == null) return;
57+
58+
Issues.Clear();
59+
ValidationScanner.GetIssues(component, Issues);
60+
if (Issues.Count == 0) return;
61+
62+
var title = $"⚠ {component.GetType().Name} needs setup";
63+
var lineHeight = EditorGUIUtility.singleLineHeight;
64+
var height = lineHeight + 6f + Issues.Count * lineHeight;
65+
66+
var rect = GUILayoutUtility.GetRect(0f, height, GUILayout.ExpandWidth(true));
67+
EditorGUI.DrawRect(rect, OrangeWash);
68+
// Solid orange edge on the left, like Unity's own message stripes.
69+
EditorGUI.DrawRect(new Rect(rect.x, rect.y, 3f, rect.height), Orange);
70+
71+
var line = new Rect(rect.x + 8f, rect.y + 3f, rect.width - 12f, lineHeight);
72+
EditorGUI.LabelField(line, title, OrangeBoldLabel);
73+
74+
foreach (var issue in Issues)
75+
{
76+
line.y += lineHeight;
77+
var text = string.IsNullOrEmpty(issue.FieldName) ? issue.Message : $"• {issue.FieldName}: {issue.Message}";
78+
EditorGUI.LabelField(line, text, OrangeLabel);
79+
}
80+
81+
EditorGUILayout.Space(2f);
82+
}
4383
}
4484
#endif
4585
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name":"fr.jeanf.propertydrawer",
3-
"version":"1.2.1",
3+
"version":"1.2.2",
44
"displayName":"Property drawer",
55
"description":"This package helps hiding certain properties from the inspector using conditions",
66
"unity": "2021.3",

0 commit comments

Comments
 (0)