Created
October 30, 2025 11:21
-
-
Save WildRikku/b977aad3a23e19597d2ce5922e43b091 to your computer and use it in GitHub Desktop.
Unity editor panel with right-clickable button
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [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; | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.