/// <summary> /// Fetches every node connection declaration for each node type for later use /// </summary> public static void FetchNodeConnectionDeclarations() { nodePortDeclarations = new Dictionary <string, ConnectionPortDeclaration[]> (); foreach (NodeTypeData nodeData in NodeTypes.GetAllNodeTypeData()) { Type nodeType = nodeData.type; List <ConnectionPortDeclaration> declarations = new List <ConnectionPortDeclaration> (); // Get all declared port fields FieldInfo[] declaredPorts = ReflectionUtility.getFieldsOfType(nodeType, typeof(ConnectionPort)); foreach (FieldInfo portField in declaredPorts) { // Get info about that port declaration using the attribute object[] declAttrs = portField.GetCustomAttributes(typeof(ConnectionPortAttribute), true); if (declAttrs.Length < 1) { continue; } ConnectionPortAttribute declarationAttr = (ConnectionPortAttribute)declAttrs[0]; if (declarationAttr.MatchFieldType(portField.FieldType)) { declarations.Add(new ConnectionPortDeclaration(portField, declarationAttr)); } else { Debug.LogError("Mismatched " + declarationAttr.GetType().Name + " for " + portField.FieldType.Name + " '" + declarationAttr.Name + "' on " + nodeData.type.Name + "!"); } } nodePortDeclarations.Add(nodeData.typeID, declarations.ToArray()); } }
public ConnectionPort CreateConnectionPort(ConnectionPortAttribute specificationAttribute) { ConnectionPort port = specificationAttribute.CreateNew(this); if (port == null) { return(null); } dynamicConnectionPorts.Add(port); ConnectionPortManager.UpdateRepresentativePortLists(this); return(port); }
//Edit to framework: (added to support inserting connection ports at an index) public ConnectionPort CreateConnectionPort(ConnectionPortAttribute specificationAttribute, int index) { if (index >= 0 && index <= dynamicConnectionPorts.Count) { ConnectionPort port = specificationAttribute.CreateNew(this); if (port == null) { return(null); } dynamicConnectionPorts.Insert(index, port); ConnectionPortManager.UpdateRepresentativePortLists(this); return(port); } return(null); }
public ConnectionPortDeclaration(FieldInfo field, ConnectionPortAttribute attr) { portField = field; portInfo = attr; }