Skip to content

Instantly share code, notes, and snippets.

@snlehton
Created January 22, 2020 10:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snlehton/26ff20e990dd035728dd3c1480ff7be6 to your computer and use it in GitHub Desktop.
Save snlehton/26ff20e990dd035728dd3c1480ff7be6 to your computer and use it in GitHub Desktop.
Various random Unity editor snippets
// 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