public static void LoadGraph(BaseGraph graph) { // Clear old graph data in case there was some specificNodeDescriptions.Remove(graph); var descriptions = new NodeDescriptions(); specificNodeDescriptions.Add(graph, descriptions); var graphType = graph.GetType(); foreach (var nodeInfo in specificNodes) { bool compatible = nodeInfo.compatibleWithGraphType == null || nodeInfo.compatibleWithGraphType == graphType; if (nodeInfo.isCompatibleWithGraph != null) { foreach (var method in nodeInfo.isCompatibleWithGraph) { compatible &= (bool)method?.Invoke(null, new object[] { graph }); } } if (compatible) { BuildCacheForNode(nodeInfo.nodeType, descriptions, graph); } } }
static void ProvideNodePortCreationDescription(Type nodeType, NodeDescriptions targetDescription, BaseGraph graph = null) { var node = Activator.CreateInstance(nodeType) as BaseNode; try { SetGraph.SetValue(node, graph); node.InitializePorts(); node.UpdateAllPorts(); } catch (Exception) { } foreach (var p in node.inputPorts) { AddPort(p, true); } foreach (var p in node.outputPorts) { AddPort(p, false); } void AddPort(NodePort p, bool input) { targetDescription.nodeCreatePortDescription.Add(new PortDescription { nodeType = nodeType, portType = p.portData.displayType ?? p.fieldInfo.FieldType, isInput = input, portFieldName = p.fieldName, portDisplayName = p.portData.displayName ?? p.fieldName, portIdentifier = p.portData.identifier, }); } }
public static void FindAllNodes() { NodeDescriptions localNodes = new NodeDescriptions(); foreach (var nodeType in TypeCache.GetTypesDerivedFrom <BaseNode>()) { var attributes = nodeType.GetCustomAttributes(typeof(NodeMenuItemAttribute), false) as NodeMenuItemAttribute[]; if (attributes != null) { foreach (var attr in attributes) { //localNodes.menutitleToNode.Add(attr.path, nodeType); } // Look for in and out fields // } // if (nodeType.IsAbstract) //return false; // skip node // return nodeType.GetCustomAttributes<NodeMenuItemAttribute>().Count() > 0; } }
public async Task Setup(CancellationToken cancellationToken) { var descriptions = await _runtime.GetNodeDescriptions(cancellationToken); foreach (var description in descriptions) { NodeDescriptions.Add(description); } }
static void BuildCacheForNode(Type nodeType, NodeDescriptions targetDescription, BaseGraph graph = null) { var attrs = nodeType.GetCustomAttributes(typeof(NodeMenuItemAttribute), false) as NodeMenuItemAttribute[]; if (attrs != null && attrs.Length > 0) { foreach (var attr in attrs) { targetDescription.nodePerMenuTitle[attr.menuTitle] = nodeType; } } foreach (var field in nodeType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { if (field.GetCustomAttribute <HideInInspector>() == null && field.GetCustomAttributes().Any(c => c is InputAttribute || c is OutputAttribute)) { targetDescription.slotTypes.Add(field.FieldType); } } ProvideNodePortCreationDescription(nodeType, targetDescription, graph); }