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 EditorHeaderItemInjector

Remarks

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

  1. Static constructor reflects on EditorGUIUtility.s_EditorHeaderItemsMethods (a List<HeaderItemDelegate>)

  2. Resolves the delegate type from the list's generic argument

  3. If the internal list is not yet initialized (editor still loading), defers injection via EditorApplication.delayCall

  4. Once 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

Goal
How

Add header GUI callback

EditorHeaderItemInjector.Inject(MyCallback)

Add at specific position

EditorHeaderItemInjector.Inject(MyCallback, index: 0)

Callback signature

Func<Rect, UnityEngine.Object[], bool>

Fields

Field
Type
Access
Description

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.

Parameter
Type
Default
Description

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)

circle-info

If called before the editor is fully initialized, the callback is queued and injected automatically once the internal list becomes available.

Common Pitfalls

circle-exclamation
circle-exclamation

Examples

Adding a Custom Header Item

See Also

Last updated