Пример #1
0
        public List <SearchTreeEntry> CreateSearchTree(SearchWindowContext context)
        {
            var tree = new List <SearchTreeEntry>();

            // First item is the title of the window
            tree.Add(new SearchTreeGroupEntry(new GUIContent("Add Node"), 0));

            // TODO: Hooks for custom top level pieces (Comments, new variables, etc)

            // Construct a tree of available nodes by module path
            var nodes = NodeReflection.GetNodeTypes();

            var groups = new SearchGroup(1);

            foreach (var node in nodes.Values)
            {
                var path = node.path;

                // Skip the node if it the module isn't whitelisted
                if (!IsInSupportedModule(path))
                {
                    continue;
                }

                // If we're coming from a port, make sure to only add nodes that accept
                // an input (or output) that's compatible.
                if (sourcePort == null || IsCompatibleWithSourcePort(node))
                {
                    var group = groups;
                    if (path != null)
                    {
                        for (int i = 0; i < path.Length; i++)
                        {
                            if (!group.subgroups.ContainsKey(path[i]))
                            {
                                group.subgroups.Add(path[i], new SearchGroup(group.depth + 1));
                            }

                            group = group.subgroups[path[i]];
                        }
                    }

                    group.nodes.Add(node);
                }
            }

            groups.AddToTree(tree);

            return(tree);
        }
        public List <SearchTreeEntry> CreateSearchTree(SearchWindowContext context)
        {
            var filter = new SearchFilter
            {
                Graph       = Target.Graph,
                SourcePort  = SourcePort?.Target,
                IncludeTags = IncludeTags
            };

            // First item is the title of the window
            var tree = new List <SearchTreeEntry>();

            tree.Add(new SearchTreeGroupEntry(new GUIContent("Add Node"), 0));

            // Construct a tree of available nodes by module path
            var groups = new SearchGroup(1);

            // Aggregate search providers and get nodes matching the filter
            foreach (var result in FilterSearchProviders(filter))
            {
                var path  = result.Path;
                var group = groups;

                if (path != null)
                {
                    // If a path is defined, drill down into nested
                    // SearchGroup entries until we find the matching directory
                    foreach (var directory in path)
                    {
                        if (!group.Subgroups.ContainsKey(directory))
                        {
                            group.Subgroups.Add(directory, new SearchGroup(group.Depth + 1));
                        }

                        group = group.Subgroups[directory];
                    }
                }

                group.Results.Add(result);
            }

            groups.AddToTree(tree);

            return(tree);
        }