public void Draw(Rect rect, TypeSelectorPopupContent selector, Action <Type> callback) { var viewRect = rect.SubXMax(16); var groupStyle = GroupStyle.Value; var totalHeight = CalcHeight(viewRect.width); var itemRect = viewRect; viewRect.height = totalHeight; using (var scope = new GUI.ScrollViewScope(rect, scrollPos, viewRect)) { scrollPos = scope.scrollPosition; foreach (var group in Subgroups) { var msg = $"{group.Name}/"; var content = new GUIContent(msg); var height = groupStyle.CalcHeight(content, itemRect.width); itemRect.height = height; var fwdArrow = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector) .GetStyle(GUIStyles.ACRightArrow); if (Event.current.type == EventType.Repaint) { fwdArrow.Draw(itemRect.SetXMin(itemRect.xMax - itemRect.height), false, false, false, false); } if (GUI.Button(itemRect, content, groupStyle)) { selector.Path.Push(group.Name); } itemRect.y += height; } DrawItems(GroupTypes, itemRect, callback); } }
public TypeSelectorButton( ModularContent <GUIContent> guiContent, Action <Type> onTypeSelected, Func <Type, TypeSelectorGroup, TypeSelectorGroup> groupSelector = null, string noElementsFoundMessage = TypeSelectorPopupContent.DefaultNoElementsFoundMessage, ModularContent <GUILayoutOption[]> guiLayoutOptions = null, params Type[] validTypes ) { this.guiContent = guiContent; this.guiLayoutOptions = guiLayoutOptions ?? new GUILayoutOption[0]; selector = new TypeSelectorPopupContent( () => lastRect.width, onTypeSelected, groupSelector, noElementsFoundMessage, validTypes ); }