static GenericMenu PrepareMenu(DropdownMenu menu, EventBase triggerEvent) { menu.PrepareForDisplay(triggerEvent); var genericMenu = new GenericMenu(); foreach (var item in menu.MenuItems()) { var action = item as DropdownMenuAction; if (action != null) { if ((action.status & DropdownMenuAction.Status.Hidden) == DropdownMenuAction.Status.Hidden || action.status == 0) { continue; } bool isChecked = (action.status & DropdownMenuAction.Status.Checked) == DropdownMenuAction.Status.Checked; if ((action.status & DropdownMenuAction.Status.Disabled) == DropdownMenuAction.Status.Disabled) { genericMenu.AddDisabledItem(new GUIContent(action.name), isChecked); } else { genericMenu.AddItem(new GUIContent(action.name), isChecked, () => { action.Execute(); }); } } else { var separator = item as DropdownMenuSeparator; if (separator != null) { genericMenu.AddSeparator(separator.subMenuPath); } } } return(genericMenu); }
/// <summary> /// Opens a dropdown anchored to the bottom border of the target rect /// </summary> /// <param name="menu"></param> /// <param name="target"></param> public void Open(DropdownMenu menu, Rect target) { if (menu == null) { throw new ArgumentNullException(nameof(menu)); } if (blockingLayer.parent != null) { Close(); } targetRect = target; menu.PrepareForDisplay(null); Build(menu); rootMenu.RegisterCallback <GeometryChangedEvent>(OnBuildComplete); root.Add(blockingLayer); }
private static GenericMenu PrepareMenu(DropdownMenu menu, EventBase triggerEvent) { menu.PrepareForDisplay(triggerEvent); GenericMenu genericMenu = new GenericMenu(); foreach (DropdownMenuItem item in menu.MenuItems()) { DropdownMenuAction action = item as DropdownMenuAction; if (action != null) { if ((action.status & DropdownMenuAction.Status.Hidden) != DropdownMenuAction.Status.Hidden && action.status != 0) { bool on = (action.status & DropdownMenuAction.Status.Checked) == DropdownMenuAction.Status.Checked; if ((action.status & DropdownMenuAction.Status.Disabled) == DropdownMenuAction.Status.Disabled) { genericMenu.AddDisabledItem(new GUIContent(action.name), on); } else { genericMenu.AddItem(new GUIContent(action.name), on, delegate { action.Execute(); }); } } } else { DropdownMenuSeparator dropdownMenuSeparator = item as DropdownMenuSeparator; if (dropdownMenuSeparator != null) { genericMenu.AddSeparator(dropdownMenuSeparator.subMenuPath); } } } return(genericMenu); }