Created
January 22, 2020 10:19
-
-
Save snlehton/26ff20e990dd035728dd3c1480ff7be6 to your computer and use it in GitHub Desktop.
Various random Unity editor snippets
This file contains 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
// Create Dropdown button | |
if (EditorGUI.DropdownButton(position, GUIContent.none, FocusType.Passive)) | |
{ | |
var genericMenu = new GenericMenu(); | |
// List<string> options | |
foreach (var option in options) | |
{ | |
bool selected = option == property.stringValue; | |
genericMenu.AddItem(new GUIContent(options), selected, () => | |
{ | |
Debug.Log(option + " selected!"); | |
}); | |
} | |
genericMenu.DropDown(position); | |
} | |
// Clear text field selection/component selection (does not work outside OnGUI) | |
EditorGUI.FocusTextInControl(null); | |
GUI.FocusControl(null); | |
// Convert local OnGUI coordinates to screen coordinates | |
var screenRect = GUIUtility.GUIToScreenRect(position); // Also GUIUtility.GUIToScreenPoint |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment