private static void BuildNodeMap() { if (_nodeContextMenuName == null) { _nodeContextMenuName = new Dictionary <Type, string>(); Type[] types = SystemUtils.GetAllSubTypes(typeof(Node)); foreach (Type type in types) { NodeCategoryAttribute nodeAttribute = SystemUtils.GetAttribute <NodeCategoryAttribute>(type); string nodeName; if (nodeAttribute != null) { if (string.IsNullOrEmpty(nodeAttribute.Category)) { nodeName = StringUtils.FromCamelCase(type.Name); } else { nodeName = nodeAttribute.Category + "/" + StringUtils.FromCamelCase(type.Name); } } else { nodeName = StringUtils.FromCamelCase(type.Name);; } _nodeContextMenuName.Add(type, nodeName); } } }
static bool TryGetCategory(Type t, out NodeCategoryAttribute value) { if (!Attribute.IsDefined(t, k_CategoryAttributeType)) { value = null; return(false); } value = (NodeCategoryAttribute)Attribute.GetCustomAttribute(t, k_CategoryAttributeType); return(value != null); }
static string CategoryString(NodeCategoryAttribute attribute) { var n = 0; s_String.Clear(); s_String.Append("node category: "); while (n < attribute.Length - 1) { s_String.AppendFormat("{0}/", attribute[n]); n++; } s_String.Append(attribute[attribute.Length - 1]); return(s_String.ToString()); }
private static void BuildNodeMap() { if (_addInputNodeContextMenu == null || _addOutputNodeContextMenu == null || _addNodeContextMenu == null) { _addNodeContextMenu = new Dictionary <Type, string>(); _addOutputNodeContextMenu = new Dictionary <Type, string>(); _addInputNodeContextMenu = new Dictionary <Type, string>(); Type[] types = SystemUtils.GetAllSubTypes(typeof(Node)); foreach (Type type in types) { NodeCategoryAttribute nodeAttribute = SystemUtils.GetAttribute <NodeCategoryAttribute>(type); string nodeName; if (nodeAttribute != null) { if (string.IsNullOrEmpty(nodeAttribute.Category)) { nodeName = StringUtils.FromCamelCase(type.Name); } else { nodeName = nodeAttribute.Category + "/" + StringUtils.FromCamelCase(type.Name); } } else { nodeName = StringUtils.FromCamelCase(type.Name);; } if (SystemUtils.IsSubclassOfRawGeneric(typeof(OutputNode <,>), type)) { Type outputType = SystemUtils.GetGenericImplementationType(typeof(OutputNode <,>), type, 1); _addOutputNodeContextMenu.Add(type, SystemUtils.GetTypeName(outputType)); } else if (SystemUtils.IsSubclassOfRawGeneric(typeof(InputNode <>), type)) { Type inputType = SystemUtils.GetGenericImplementationType(typeof(InputNode <>), type); _addInputNodeContextMenu.Add(type, SystemUtils.GetTypeName(inputType)); } else { _addNodeContextMenu.Add(type, nodeName); } } } }
void NestInsert(NodeCategoryAttribute attribute, string typeLabel) { Dictionary <string, Dictionary <string, List <string> > > topLevelEntry; if (m_Nest.TryGetValue(attribute[0], out topLevelEntry)) { Dictionary <string, List <string> > secondLevel; if (topLevelEntry.TryGetValue(attribute[1], out secondLevel)) { List <string> thirdLevel; if (secondLevel.TryGetValue(attribute[2], out thirdLevel)) { thirdLevel.Add(typeLabel); } else { secondLevel.Add(attribute[2], new List <string> { typeLabel }); } } //topLevelEntry[attribute[1]][attribute[2]].Add(typeLabel); } else { topLevelEntry = new Dictionary <string, Dictionary <string, List <string> > >(); var thirdDict = new Dictionary <string, List <string> >(); var leafList = new List <string> { typeLabel }; thirdDict.Add(attribute[2], leafList); topLevelEntry.Add(attribute[1], thirdDict); m_Nest.Add(attribute[0], topLevelEntry); } }