//Generate the tree node structure out of the items
 static void GenerateTree()
 {
     loadProgress = 0;
     items        = EditorUtils.GetMenuItems(boundMenu);
     leafNodes    = new List <Node>();
     for (var i = 0; i < items.Length; i++)
     {
         loadProgress = i / (float)items.Length;
         var  item     = items[i];
         var  itemPath = item.content.text;
         var  parts    = itemPath.Split('/');
         Node current  = rootNode;
         var  path     = string.Empty;
         for (var j = 0; j < parts.Length; j++)
         {
             var part = parts[j];
             path += "/" + part;
             Node child = null;
             if (!current.children.TryGetValue(part, out child))
             {
                 child = new Node {
                     name = part, parent = current
                 };
                 child.fullPath         = path;
                 current.children[part] = child;
                 if (part == parts.Last())
                 {
                     child.item = item;
                     leafNodes.Add(child);
                 }
             }
             current = child;
         }
     }
 }
示例#2
0
 //init
 public CompleteContextMenu(GenericMenu menu, string title)
 {
     this.items = EditorUtils.GetMenuItems(menu);
     rootNode   = new Node();
     GenerateTree();
     currentNode           = rootNode;
     this.title            = title;
     headerStyle           = new GUIStyle("label");
     headerStyle.alignment = TextAnchor.UpperCenter;
 }
 //init
 public CompleteContextMenu(GenericMenu menu, string title, System.Type keyType)
 {
     this.title            = title;
     currentKeyType        = keyType;
     items                 = EditorUtils.GetMenuItems(menu);
     rootNode              = new Node();
     currentNode           = rootNode;
     headerStyle           = new GUIStyle("label");
     headerStyle.alignment = TextAnchor.UpperCenter;
     GenerateTree();
     hoveringIndex = -1;
 }