Exemple #1
0
        private static void InitMenu(string path, RecursiveNode node, GenericMenu menu, bool isPreview)
        {
            string fullPath = path + node.label;

            // if(path.Length > 0) {  }


            if (node.type == NodeType.Separator)
            {
                menu.AddSeparator(path);
            }
            else if (node.type == NodeType.Command)
            {
                var label = new GUIContent(fullPath);
                if (isPreview)
                {
                    menu.AddDisabledItem(label);
                }
                else
                {
                    menu.AddItem(label, false, () =>
                    {
                        Utils.ExecuteCommandString(node.command);
                    });
                }
            }
            else
            {
                foreach (var n in node.children)
                {
                    InitMenu(fullPath + "/", n, menu, isPreview);
                }
            }
        }
Exemple #2
0
 private static void SortChildren(RecursiveNode n)
 {
     if (n.children.Count > 0)
     {
         n.children = n.children.OrderBy(x => x.yPos).ToList();
         foreach (var c in n.children)
         {
             SortChildren(c);
         }
     }
 }
Exemple #3
0
        public static GenericMenu GetMenu(this RecursiveNode root, bool isPreview = false)
        {
            GenericMenu m = new GenericMenu();

            foreach (var c in root.children)
            {
                InitMenu("", c, m, isPreview);
            }

            return(m);
        }
Exemple #4
0
        public static RecursiveNode GetRecursive(this ContextGraph graph)
        {
            if (graph.RootNode == null)
            {
                return(null);
            }
            Dictionary <string, RecursiveNode> nodes = new Dictionary <string, RecursiveNode>();

            foreach (var n in graph.Nodes)
            {
                var rn = new RecursiveNode
                {
                    id      = n.id,
                    label   = n.label,
                    command = n.command,
                    type    = n.Type,
                    yPos    = n.position.y
                };
                nodes.Add(rn.id, rn);
            }

            // check if there's a root node set
            RecursiveNode rootNode;

            if (!nodes.TryGetValue(graph.RootNode, out rootNode))
            {
                return(null);
            }



            foreach (var e in graph.Edges)
            {
                RecursiveNode from, to;
                if (!nodes.TryGetValue(e.from, out from))
                {
                    continue;
                }
                if (!nodes.TryGetValue(e.to, out to))
                {
                    continue;
                }
                from.children.Add(to);
            }
            SortChildren(rootNode);

            return(rootNode);
        }