static void PopulateNodeMenu( Menu menu, IEnumerable<INodeType> nodes, System.Nullable<NodeQuery> query, System.Action<INodeType> selectedAction )

book_4_sparkGenerated
code_blocksInput

Description

The PopulateNodeMenu method is a static method of the GraphView class within the Editor.NodeEditor namespace. This method is used to populate a given menu with node types that can be added to a node editor graph. It allows for filtering of nodes based on a query and executes a specified action when a node type is selected from the menu.

Usage

To use the PopulateNodeMenu method, you need to provide the following parameters:

  • menu: An instance of Editor.Menu where the node types will be added as menu items.
  • nodes: An IEnumerable<INodeType> collection representing the available node types to be added to the menu.
  • query: An optional NodeQuery that can be used to filter the node types based on specific criteria.
  • selectedAction: An Action<INodeType> delegate that defines the action to be executed when a node type is selected from the menu.

Example

// Example usage of PopulateNodeMenu
Editor.Menu menu = new Editor.Menu();
IEnumerable<Editor.NodeEditor.INodeType> nodeTypes = GetAvailableNodeTypes();
Editor.NodeEditor.NodeQuery? query = GetNodeQuery();

Editor.NodeEditor.GraphView.PopulateNodeMenu(
    menu,
    nodeTypes,
    query,
    nodeType => {
        // Action to perform when a node type is selected
        AddNodeToGraph(nodeType);
    }
);

// Function to retrieve available node types
IEnumerable<Editor.NodeEditor.INodeType> GetAvailableNodeTypes()
{
    // Implementation to return node types
}

// Function to retrieve a node query
Editor.NodeEditor.NodeQuery? GetNodeQuery()
{
    // Implementation to return a node query
}

// Function to add a node to the graph
void AddNodeToGraph(Editor.NodeEditor.INodeType nodeType)
{
    // Implementation to add the node
}