Exemple #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 IEnumerable <SearchResult> GetSearchResults(SearchFilter filter)
 {
     foreach (var entry in NodeReflection.GetNodeTypes())
     {
         var node = entry.Value;
         if (
             IsCompatible(filter.SourcePort, node) &&
             IsInSupportedTags(filter.IncludeTags, node.Tags)
             )
         {
             yield return(new SearchResult
             {
                 Name = node.Name,
                 Path = node.Path,
                 UserData = node,
             });
         }
     }
 }