Skip to content

Instantly share code, notes, and snippets.

@WildRikku
Created October 30, 2025 11:21
Show Gist options
  • Select an option

  • Save WildRikku/b977aad3a23e19597d2ce5922e43b091 to your computer and use it in GitHub Desktop.

Select an option

Save WildRikku/b977aad3a23e19597d2ce5922e43b091 to your computer and use it in GitHub Desktop.
Unity editor panel with right-clickable button
[Overlay(typeof(SceneView), "SceneViewDemo", true)]
public class SceneViewDemo : Overlay {
public override VisualElement CreatePanelContent() {
VisualElement root = new() { name = "SceneViewDemo" };
Button btn = new() {
text = "Hello World";
};
btn.clickable.activators.Add(new() {
button = MouseButton.RightMouse
});
btn.clickable.clickedWithEventInfo += eventBase => {
if (eventBase is MouseUpEvent mouseUpEvent) {
switch (mouseUpEvent.button) {
case 0:
// left click
break;
case 1:
// right click
break;
}
}
};
root.Add(btn);
return root;
}
}
@WildRikku
Copy link
Author

The documentation for scene view panels is a little sparse and the UI toolkit buttons don't support right-clicking out of the box, so here's a code snippet to add a right-clickable button to a scene view panel and distinguish which mouse button was used. Tested in Unity 2022.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment