public bool DoLayout(GUIStyle style) { // Creating Layout element var id = GUIUtility.GetControlID(Label.GetHashCode(), FocusType.Keyboard); if (Event.current.type == EventType.Used) { if (Drop.IsShowing(id)) { Drop.Hide(id); Drop.Update(id, Elements); } if (GUI.GetNameOfFocusedControl() == id.ToString()) { GUI.FocusControl(null); } } GUI.SetNextControlName(id.ToString()); if (style == null) { Value = EditorGUILayout.TextField(Label, Value); } else { Value = EditorGUILayout.TextField(Label, Value, style); } // Calculating dropdown scroll rect var addressRect = GUILayoutUtility.GetLastRect(); var r = selected; if (selected) { this.Elements.Clear(); selected = false; this.Value = nextValue; } else { // If focused show if ((Event.current.type == EventType.Repaint || Event.current.type == EventType.MouseMove) && GUI.GetNameOfFocusedControl() == id.ToString() && Elements != null && Elements.Count > 0) { if (!Drop.IsShowing(id)) { Drop.ShowAt(id, addressRect, Elements, OnOptionSelected); } Drop.Update(id, Elements); } if (GUI.GetNameOfFocusedControl() != id.ToString() && Drop.IsShowing(id) || (Event.current.type == EventType.MouseDown && !addressRect.Contains(Event.current.mousePosition))) { Drop.Hide(id); Drop.Update(id, Elements); GUI.FocusControl(null); } } return(r); }