private void GenerateMenu(MenuItemBase contextMenu, GenericMenu genericMenu, string path) { if (contextMenu.Count > 0) { for (int i = 0; i < contextMenu.Count; i++) { MenuItem item = contextMenu[i]; if (item == null) { if (string.IsNullOrEmpty(path)) { genericMenu.AddSeparator(string.Empty); } else { genericMenu.AddSeparator(path + "/"); } } else { item.Path = item.Name; if (!string.IsNullOrEmpty(path)) { item.Path = string.Format("{0}/{1}", path, item.Name); } if (item.Count > 0) { GenerateMenu(item, genericMenu, item.Path); } else if (item.IsVisible) { GUIContent content = new GUIContent(); content.text = item.Path; content.image = item.Image; content.tooltip = item.Tooltip; if (item.IsEnabled) { _GenericMenu.AddItem(content, item.IsChecked, _MenuFunction, item); } else { _GenericMenu.AddDisabledItem(content); } } } } } contextMenu.CalcHeight(ItemHeight, SeparatorHeight); }
private EventTrackBarContextMenu() { // find all event class List <EventInfo> events = new List <EventInfo>(); Type baseType = typeof(EventKey); foreach (System.Reflection.Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) { foreach (Type objType in assembly.GetTypes()) { if ((objType.IsPublic && ((objType.Attributes & System.Reflection.TypeAttributes.Abstract) != System.Reflection.TypeAttributes.Abstract)) && objType.IsSubclassOf(baseType)) { object[] customEventAttributes = objType.GetCustomAttributes(typeof(CustomEventAttribute), true); if (customEventAttributes != null && customEventAttributes.Length > 0) { CustomEventAttribute att = (CustomEventAttribute)customEventAttributes[0]; EventInfo info = new EventInfo(); info.DisplayName = att.DisplayName; info.Path = string.IsNullOrEmpty(att.Path) ? "Custom" : att.Path.Trim(' ', '/', '\\', ',', '.').Replace('\\', '/'); info.Type = objType; info.Assembly = assembly; events.Add(info); } } } } List <MenuItemData> itemList = new List <MenuItemData>(); foreach (var e in events) { Skill.Editor.UI.MenuItem pathItem = FindItem(itemList, e.Path); if (pathItem == null) { string[] pathParts = e.Path.Split('/'); if (pathParts == null || pathParts.Length == 0) { pathParts = new string[] { "Custom" } } ; string path = string.Empty; Skill.Editor.UI.MenuItemBase parentItem = this; for (int i = 0; i < pathParts.Length; i++) { path += pathParts[i]; pathItem = FindItem(itemList, path); if (pathItem == null) { pathItem = new UI.MenuItem(pathParts[i]); itemList.Add(new MenuItemData() { Path = path, Item = pathItem }); parentItem.Add(pathItem); } parentItem = pathItem; path += "/"; } } if (pathItem != null) { Skill.Editor.UI.MenuItem addItem = new UI.MenuItem(e.DisplayName) { UserData = e }; addItem.Click += addItem_Click; pathItem.Add(addItem); } } }