EditorHeaderItemInjector
Static utility that injects custom GUI callbacks into Unity's internal Editor header item list via reflection. Header items appear in the Inspector header area for UnityEngine.Object targets.
Definition
Namespace: Paragon.Editor.LowLevel Assembly: Paragon.Editor.dll
public static class EditorHeaderItemInjectorRemarks
Unity maintains an internal list of header item delegates in EditorGUIUtility.s_EditorHeaderItemsMethods. This static class uses reflection to access that list and inject custom callbacks at a specified index.
Initialization Flow
Static constructor reflects on
EditorGUIUtility.s_EditorHeaderItemsMethods(aList<HeaderItemDelegate>)Resolves the delegate type from the list's generic argument
If the internal list is not yet initialized (editor still loading), defers injection via
EditorApplication.delayCallOnce initialized, flushes any queued callbacks into the list
Deferred Injection
Calls to Inject before Unity's header items list is ready are queued in methodsAwaitingInjection. Once Initialize() succeeds, all queued callbacks are injected in order.
Quick Lookup
Add header GUI callback
EditorHeaderItemInjector.Inject(MyCallback)
Add at specific position
EditorHeaderItemInjector.Inject(MyCallback, index: 0)
Callback signature
Func<Rect, UnityEngine.Object[], bool>
Fields
headerItemMethodDelegateType
Type
private static readonly
The delegate type used by Unity's internal header items list
initialized
bool
private static
Whether the internal list has been resolved and is ready
headerItemsMethodsField
FieldInfo
private static readonly
Reflected field for EditorGUIUtility.s_EditorHeaderItemsMethods
methodsAwaitingInjection
List<Func<Rect, Object[], bool>>
private static readonly
Queue of callbacks waiting for initialization
Methods
Inject
Registers a callback to be drawn in the Inspector header area.
callback
Func<Rect, Object[], bool>
—
GUI callback receiving the header rect and target objects. Return true if handled.
index
int
0
Position in the header items list (0 = first)
If called before the editor is fully initialized, the callback is queued and injected automatically once the internal list becomes available.
Common Pitfalls
Unity internals dependency This class reflects on EditorGUIUtility.s_EditorHeaderItemsMethods, which is a private static field. Changes to Unity's internal API between versions may break this functionality silently.
Callback delegate conversion The injected Func<Rect, Object[], bool> is converted to Unity's internal HeaderItemDelegate type via CreateDelegate. The callback method must be a static method — instance method delegates will throw.
Examples
Adding a Custom Header Item
See Also
LowLevel Overview — subsystem overview
OnGUIInjector — similar injection for editor window OnGUI
Last updated