Skip to content

Instantly share code, notes, and snippets.

Last active February 27, 2023 16:24
What would you like to do?
Adds a UI element to the Unity 2022.1 toolbar using reflection.
var toolbarType = Assembly
var toolbar = toolbarType
.GetField("get", BindingFlags.Public | BindingFlags.Static)!
var toolbarRootVisualElement = toolbarType
.GetField("m_Root", BindingFlags.Instance | BindingFlags.NonPublic)!
.GetValue(toolbar) as VisualElement;
var rightToolbar = toolbarRootVisualElement.Q("ToolbarZoneRightAlign");
rightToolbar.Add(new EditorToolbarButton(() =>
}) { text = "Click Me" });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment