/// <summary> /// Parse the path for the menu item and add any group items required /// </summary> /// <param name="menuItem"></param> private void AddHierarchy(GUIGenericMenuItem menuItem) { if (menuItem.Path.Trim() == string.Empty) { return; } string[] splits = menuItem.Path.Split(new char[] { '/' }); for (int i = 0; i < splits.Length; i++) { string currentPath = string.Empty; for (int c = 0; c < i; c++) { if (!string.IsNullOrEmpty(currentPath)) { currentPath += "/"; } currentPath += splits[c]; } Internal_AddMenuItem(new GUIGroupMenuItem(currentPath, new GUIContent(splits[i]), AddPathToActive)); } }
/// <summary> /// Constructor /// </summary> /// <param name="selectedItem">The item that launched the event</param> /// <param name="menuContext">The context the menu was opened for</param> public GUIMenuItemEventArgs(GUIGenericMenuItem selectedItem, System.Object menuContext) { SelectedItem = selectedItem; MenuContext = menuContext; ItemText = selectedItem.Display.text; }
/// <summary> /// Determines if the provided item is currently selected /// Applies specialized logic in the case of a Group item /// </summary> /// <param name="item">The item to query</param> /// <param name="itemRect">The rectangle of the item</param> /// <returns>True if selected, false if not</returns> private bool IsItemSelected(GUIGenericMenuItem item, Rect itemRect) { if (itemRect.Contains(Event.current.mousePosition)) { canRemove = true; selectedItem = item; return(true); } if (item is GUIGroupMenuItem && selectedPaths.Find((x) => x.Path.Equals(item.Path)) != null) { return(true); } return(false); }
/// <summary> /// Renders the menu item if it's currently shown /// </summary> public void Draw() { selectedItem = null; if (!IsShown) { return; } List <GUIGenericMenuItem> rootGroup; if (!groupedMenuItems.TryGetValue(string.Empty, out rootGroup)) { return; } DrawGroup(new Rect(drawPosition, Vector2.zero), string.Empty, rootGroup); for (int i = 0; i < selectedPaths.Count; i++) { GUIGroupMenuItem groupItem = selectedPaths[i]; List <GUIGenericMenuItem> nestedGroup; string nextGroup = groupItem.Path; if (!string.IsNullOrEmpty(nextGroup)) { nextGroup += "/"; } nextGroup += groupItem.Display.text; if (!groupedMenuItems.TryGetValue(nextGroup, out nestedGroup)) { continue; } Rect rect = DrawGroup(groupItem.PositionRect, nextGroup, nestedGroup); if (i == selectedPaths.Count - 1) { deepestRect = rect; } } }
/// <summary> /// Add a menu item to the appropriate list stored within the dictionary /// </summary> /// <param name="menuItem">The item to be added</param> private void Internal_AddMenuItem(GUIGenericMenuItem menuItem) { List <GUIGenericMenuItem> existing; if (!groupedMenuItems.TryGetValue(menuItem.Path, out existing)) { existing = new List <GUIGenericMenuItem>(); groupedMenuItems.Add(menuItem.Path, existing); } GUIGenericMenuItem existingItem = existing.Find((x) => !string.IsNullOrEmpty(x.Display.text) && x.Display.text == menuItem.Display.text); if (existingItem != null) { return; } existing.Add(menuItem); }
/// <summary> /// Adds the provided menu item to the list /// </summary> /// <param name="item">The item to be added</param> public void AddMenuItem(GUIGenericMenuItem item) { AddHierarchy(item); Internal_AddMenuItem(item); }
/// <summary> /// Constructor /// </summary> /// <param name="selectedItem">The item that launched the event</param> /// <param name="menuContext">The context the menu was opened for</param> /// <param name="paramValue">The data stored with the menu item to be passed along</param> public GUIMenuItemParamEventArgs(GUIGenericMenuItem selectedItem, object menuContext, System.Object paramValue) : base(selectedItem, menuContext) { ParamValue = paramValue; }