private static void CachePorts(System.Type nodeType) { List <System.Reflection.FieldInfo> fieldInfo = GetNodeFields(nodeType); for (int i = 0; i < fieldInfo.Count; i++) { //Get InputAttribute and OutputAttribute object[] attribs = fieldInfo[i].GetCustomAttributes(true); Node.InputAttribute inputAttrib = attribs.FirstOrDefault(x => x is Node.InputAttribute) as Node.InputAttribute; Node.OutputAttribute outputAttrib = attribs.FirstOrDefault(x => x is Node.OutputAttribute) as Node.OutputAttribute; if (inputAttrib == null && outputAttrib == null) { continue; } if (inputAttrib != null && outputAttrib != null) { Debug.LogError("Field " + fieldInfo[i].Name + " of type " + nodeType.FullName + " cannot be both input and output."); } else { if (!portDataCache.ContainsKey(nodeType)) { portDataCache.Add(nodeType, new List <NodePort>()); } portDataCache[nodeType].Add(new NodePort(fieldInfo[i])); } } }
/// <summary>Returns true if the given port is in a dynamic port list.</summary> private static bool IsDynamicListPort(NodePort port) { // Ports flagged as "dynamicPortList = true" end up having a "backing port" and a name with an index, but we have // no guarantee that a dynamic port called "output 0" is an element in a list backed by a static "output" port. // Thus, we need to check for attributes... (but at least we don't need to look at all fields this time) string[] fieldNameParts = port.fieldName.Split(' '); if (fieldNameParts.Length != 2) { return(false); } FieldInfo backingPortInfo = port.node.GetType().GetField(fieldNameParts[0]); if (backingPortInfo == null) { return(false); } object[] attribs = backingPortInfo.GetCustomAttributes(true); return(attribs.Any(x => { Node.InputAttribute inputAttribute = x as Node.InputAttribute; Node.OutputAttribute outputAttribute = x as Node.OutputAttribute; return inputAttribute != null && inputAttribute.dynamicPortList || outputAttribute != null && outputAttribute.dynamicPortList; })); }
private static void CachePorts(System.Type nodeType) { List <System.Reflection.FieldInfo> fieldInfo = GetNodeFields(nodeType); for (int i = 0; i < fieldInfo.Count; i++) { //Get InputAttribute and OutputAttribute object[] attribs = fieldInfo[i].GetCustomAttributes(true); Node.InputAttribute inputAttrib = attribs.FirstOrDefault(x => x is Node.InputAttribute) as Node.InputAttribute; Node.OutputAttribute outputAttrib = attribs.FirstOrDefault(x => x is Node.OutputAttribute) as Node.OutputAttribute; UnityEngine.Serialization.FormerlySerializedAsAttribute formerlySerializedAsAttribute = attribs.FirstOrDefault(x => x is UnityEngine.Serialization.FormerlySerializedAsAttribute) as UnityEngine.Serialization.FormerlySerializedAsAttribute; if (inputAttrib == null && outputAttrib == null) { continue; } if (inputAttrib != null && outputAttrib != null) { Debug.LogError("Field " + fieldInfo[i].Name + " of type " + nodeType.FullName + " cannot be both input and output."); } else { if (!portDataCache.ContainsKey(nodeType)) { portDataCache.Add(nodeType, new List <NodePort>()); } portDataCache[nodeType].Add(new NodePort(fieldInfo[i])); } if (formerlySerializedAsAttribute != null) { if (formerlySerializedAsCache == null) { formerlySerializedAsCache = new Dictionary <System.Type, Dictionary <string, string> >(); } if (!formerlySerializedAsCache.ContainsKey(nodeType)) { formerlySerializedAsCache.Add(nodeType, new Dictionary <string, string>()); } if (formerlySerializedAsCache[nodeType].ContainsKey(formerlySerializedAsAttribute.oldName)) { Debug.LogError("Another FormerlySerializedAs with value '" + formerlySerializedAsAttribute.oldName + "' already exist on this node."); } else { formerlySerializedAsCache[nodeType].Add(formerlySerializedAsAttribute.oldName, fieldInfo[i].Name); } } } }
private static void CachePorts(System.Type nodeType) { List <System.Reflection.FieldInfo> fieldInfo = GetNodeFields(nodeType); System.Type baseType = typeof(NodeLink); for (int i = 0; i < fieldInfo.Count; i++) { //Get InputAttribute and OutputAttribute FieldInfo field = fieldInfo[i]; object[] attribs = field.GetCustomAttributes(true); Node.InputAttribute inputAttrib = attribs.FirstOrDefault(x => x is Node.InputAttribute) as Node.InputAttribute; Node.OutputAttribute outputAttrib = attribs.FirstOrDefault(x => x is Node.OutputAttribute) as Node.OutputAttribute; if (inputAttrib == null && outputAttrib == null) { continue; } if (inputAttrib != null && outputAttrib != null) { Debug.LogError("Field " + field.Name + " of type " + nodeType.FullName + " cannot be both input and output."); } else { System.Type linkType = field.FieldType; System.Type type = field.FieldType; bool isNodeLink = baseType.IsAssignableFrom(type); System.Type genericType = type.IsGenericType ? type.GetGenericTypeDefinition() : null; bool isNodeLinkList = false; if (genericType == typeof(List <>)) { linkType = type.GetGenericArguments() [0]; isNodeLinkList = baseType.IsAssignableFrom(linkType); } if (isNodeLink || isNodeLinkList) { if (!linkCache.ContainsKey(nodeType)) { linkCache.Add(nodeType, new List <NodeLinkDefinition>()); } linkCache[nodeType].Add(new NodeLinkDefinition { IsList = isNodeLinkList, LinkType = linkType, FieldType = type, InputAttribute = inputAttrib, OutputAttribute = outputAttrib, FieldName = field.Name, FieldInfo = field, }); } else { if (!portDataCache.ContainsKey(nodeType)) { portDataCache.Add(nodeType, new List <NodePort>()); } portDataCache[nodeType].Add(new NodePort(field)); } } } }