protected virtual void AddTreeEntry(List <SearchTreeEntry> entries, BetterSearchTree <T> tree, int level) { // Add Leaf element if (tree.IsLeaf) { var entry = new SearchTreeEntry(tree.label) { level = level, userData = tree.payload }; entries.Add(entry); } // Add Group else { var group = new SearchTreeGroupEntry(new GUIContent(tree.label.text), level); entries.Add(group); // Add children foreach (var child in tree.children) { AddTreeEntry(entries, child, level + 1); } } }
internal void AddToTree(List <SearchTreeEntry> tree) { SearchTreeEntry entry; // Add subgroups foreach (var group in Subgroups) { GUIContent content = new GUIContent(" " + group.Key, folderIcon); entry = new SearchTreeGroupEntry(content) { level = Depth }; tree.Add(entry); group.Value.AddToTree(tree); } // Add nodes foreach (var result in Results) { GUIContent content = new GUIContent(" " + result.Name); entry = new SearchTreeEntry(content) { level = Depth, userData = result }; tree.Add(entry); } }
//public void Initialize(BaseGraphView _graphView, IEnumerable<Type> _nodeTypes, NodePort _port, Action<BaseNode> _onNodeCreated) //{ // graphView = _graphView; // port = _port; // nodeTypes = _nodeTypes; // tree = foreach (var item in GraphProcessorCache.PortCache) // { // foreach (var cachedPort in item.Value) // { // if (NodePort.IsCompatible(port, cachedPort)) // yield return item.Key; // } // } // onNodeCreated = _onNodeCreated; //} private List <SearchTreeEntry> CreateSearchTree() { List <SearchTreeEntry> tempTree = new List <SearchTreeEntry>() { new SearchTreeGroupEntry(new GUIContent("Create Elements")) }; foreach (Type type in nodeTypes) { if (Utility_Attribute.TryGetTypeAttribute(type, out NodeMenuItemAttribute attribute)) { if (attribute.showInList) { if (attribute.titles.Length > 1) { SearchTreeGroupEntry groupTemp = null; for (int i = 1; i < attribute.titles.Length; i++) { SearchTreeGroupEntry group = tempTree.Find(item => (item.content.text == attribute.titles[i - 1] && item.level == i)) as SearchTreeGroupEntry; if (group == null) { group = new SearchTreeGroupEntry(new GUIContent(attribute.titles[i - 1]), i); int index = groupTemp == null ? 0 : tempTree.IndexOf(groupTemp); tempTree.Insert(index + 1, group); } groupTemp = group; } tempTree.Insert(tempTree.IndexOf(groupTemp) + 1, new SearchTreeEntry(new GUIContent(attribute.titles.Last())) { userData = type, level = attribute.titles.Length }); } else { tempTree.Add(new SearchTreeEntry(new GUIContent(attribute.titles.Last())) { userData = type, level = 1 }); } } } else { GUIContent content = new GUIContent(GraphProcessorEditorUtility.GetNodeDisplayName(type)); tempTree.Add(new SearchTreeEntry(content) { userData = type, level = 1 }); } } return(tempTree); }
private static SearchTreeGroupEntry GetOrCreateGroupEntryForPath([NotNull] List <SearchTreeEntry> tree, [NotNull] SearchTreeGroupEntry baseEntry, [NotNull] string groupPath) { string[] groups = groupPath.Split('/'); for (int i = 0, count = groups.Length; i < count; ++i) { string group = groups[i]; baseEntry = GetOrAddGroupEntry(tree, baseEntry, group); } return(baseEntry); }
private static int IndexOfNextGroup([NotNull] List <SearchTreeEntry> tree, [NotNull] SearchTreeGroupEntry start) { int index = tree.IndexOf(start) + 1; for (int count = tree.Count; index < count; ++index) { SearchTreeEntry entry = tree[index]; if (entry.level <= start.level && entry is SearchTreeGroupEntry) { break; } } return(index); }
private static void AddEntries([NotNull] List <SearchTreeEntry> tree, [NotNull] List <Type> behaviorTypes, [NotNull] SearchTreeGroupEntry mainGroupEntry) { for (int i = 0, count = behaviorTypes.Count; i < count; ++i) { Type behaviorType = behaviorTypes[i]; SerializedBehaviorsCollection.TryGetSerializedBehaviorType(behaviorType, out Type serializedBehaviorType); var groupNameAttribute = serializedBehaviorType.GetCustomAttribute <SearchGroupAttribute>(); SearchTreeGroupEntry groupEntry = groupNameAttribute == null ? mainGroupEntry : GetOrCreateGroupEntryForPath(tree, mainGroupEntry, groupNameAttribute.groupPath); var entry = new SearchTreeEntry(new GUIContent(TypeHelper.GetUIName(behaviorType))) { level = groupEntry.level + 1, userData = serializedBehaviorType }; tree.Insert(IndexOfNextGroup(tree, groupEntry), entry); } }
private static SearchTreeGroupEntry GetOrAddGroupEntry([NotNull] List <SearchTreeEntry> tree, [NotNull] SearchTreeGroupEntry baseEntry, [NotNull] string groupName) { int baseIndex = tree.IndexOf(baseEntry); int finalIndex = baseIndex + 1; int level = baseEntry.level + 1; for (int count = tree.Count; finalIndex < count; ++finalIndex) { SearchTreeEntry treeEntry = tree[finalIndex]; if (treeEntry.level <= baseEntry.level) { break; } if (treeEntry is SearchTreeGroupEntry groupEntry && groupEntry.level == level && groupEntry.content.text == groupName) { return(groupEntry); } } int index = baseIndex + 1; for (; index < finalIndex; ++index) { SearchTreeEntry element = tree[index]; if (element.level == level && string.CompareOrdinal(groupName, element.content.text) < 0) { break; } } var entry = new SearchTreeGroupEntry(new GUIContent(groupName), level); tree.Insert(index, entry); return(entry); }
public void AddToTree(List <SearchTreeEntry> tree) { SearchTreeEntry entry; // Add subgroups foreach (var group in subgroups) { entry = new SearchTreeGroupEntry(new GUIContent(group.Key)); entry.level = depth; tree.Add(entry); group.Value.AddToTree(tree); } // Add nodes foreach (var node in nodes) { entry = new SearchTreeEntry(new GUIContent(node.name)); entry.level = depth; entry.userData = node; tree.Add(entry); } }
override public List <SearchTreeEntry> CreateSearchTree(SearchWindowContext context) { if (_slowRegistryCache != null && _slowRegistryCache.Count > 0) { return(_slowRegistryCache); } _slowRegistryCache = new List <SearchTreeEntry> { new SearchTreeGroupEntry(new GUIContent("Full Search"), 0) }; var topRegistries = UdonEditorManager.Instance.GetTopRegistries(); Texture2D icon = null; var groupEntries = new Dictionary <string, SearchTreeGroupEntry>(); foreach (var topRegistry in topRegistries) { string topName = topRegistry.Key.Replace("NodeRegistry", ""); if (topName != "Udon") { _slowRegistryCache.Add(new SearchTreeGroupEntry(new GUIContent(topName), 1)); } // get all registries, save into registryName > INodeRegistry Lookup var subRegistries = new Dictionary <string, INodeRegistry>(); foreach (KeyValuePair <string, INodeRegistry> registry in topRegistry.Value.OrderBy(s => s.Key)) { string baseRegistryName = registry.Key.Replace("NodeRegistry", "").FriendlyNameify().ReplaceFirst(topName, ""); string registryName = baseRegistryName.UppercaseFirst(); subRegistries.Add(registryName, registry.Value); } // Go through each registry entry and add the top-level registry and associated array registry foreach (KeyValuePair <string, INodeRegistry> regEntry in subRegistries) { INodeRegistry registry = regEntry.Value; string registryName = regEntry.Key; int level = 2; // Special cases for Udon sub-levels, added at top if (topName == "Udon") { level = 1; if (registryName == "Event" || registryName == "Type") { registryName = $"{registryName}s"; } } if (!registryName.EndsWith("[]")) { // add Registry Level var groupEntry = new SearchTreeGroupEntry(new GUIContent(registryName, icon), level) { userData = registry }; _slowRegistryCache.Add(groupEntry); } // Check for Array Type first string regArrayType = $"{registryName}[]"; if (subRegistries.TryGetValue(regArrayType, out INodeRegistry arrayRegistry)) { // we have a matching subRegistry, add that next var arrayLevel = level + 1; var arrayGroupEntry = new SearchTreeGroupEntry(new GUIContent(regArrayType, icon), arrayLevel) { userData = registry }; _slowRegistryCache.Add(arrayGroupEntry); // Add all array entries AddEntriesForRegistry(_slowRegistryCache, arrayRegistry, arrayLevel + 1); } AddEntriesForRegistry(_slowRegistryCache, registry, level + 1, true); } } return(_slowRegistryCache); }
public SearchGroup(SearchTreeGroupEntry firstEntry) { level = firstEntry.level; entries.Add(firstEntry); }
/* * Top level * Categories * * 2nd level * Generic type definitions * * 3rd level * concrete type implementations */ void SetupTree() { Instance = this; k_Entries.Clear(); k_EntryBuffer.Clear(); k_VisionNodeTypes.Clear(); k_VisionNodeTypeBuffer.Clear(); m_TypeLookup.Clear(); m_Groups.Clear(); var nodeType = typeof(VisionNode); k_Assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (var ass in k_Assemblies) { foreach (var type in ass.GetTypes()) { if (type.IsAbstract) // ignore types we can't instantiate { continue; } // right now, we're sticking to explicit concrete implementations //if (type.IsGenericTypeDefinition) // continue; NodeCategoryAttribute attribute; if (!TryGetCategory(type, out attribute)) { continue; } if (type.IsSubclassOf(nodeType)) { k_VisionNodeTypes.Add(type); } } } // the underlying code tries to add your first search tree entry as a group, // and gets a null ref if you don't because the cast. fails var initialGroupEntry = new SearchTreeGroupEntry(new GUIContent("Search")); k_Entries.Add(initialGroupEntry); foreach (var t in k_VisionNodeTypes) { m_TypeLookup.Add(t.Name, t); var guiContent = new GUIContent(t.Name); NodeCategoryAttribute attribute; if (!TryGetCategory(t, out attribute)) { continue; } Debug.Log(CategoryString(attribute)); //var depth = attribute.Length + 1; //var entry = new SearchTreeEntry(guiContent) {level = depth, userData = new object()}; NestInsert(attribute, t.Name); /* * Dictionary<string, Dictionary<string, List<string>>> topLevelEntries; * if (m_Nest.TryGetValue(attribute[0], out topLevelEntries)) * { * var secondDict = new Dictionary<string, Dictionary<string, List<string>>>(); * var thirdDict = new Dictionary<string, List<string>>(); * var leafList = new List<string>(); * searchGroup.AddEntry(entry); * } * else * { * var searchContent = new GUIContent(attribute[0]); * var firstEntry = new SearchTreeGroupEntry(searchContent) {level = 1}; * var group = new SearchGroup(firstEntry); * group.AddEntry(entry); * * if (depth <= 1) * continue; * * var depthCount = 0; * while(depthCount < depth - 1) * { * var newEntry = new SearchTreeGroupEntry(new GUIContent(attribute[depthCount])) * { * level = depthCount + 2 * }; * depthCount++; * } * * m_Nest.Add(attribute[0], group); * } */ } foreach (var topLevelKvp in m_Nest) { var firstLevelLabel = topLevelKvp.Key; var firstLevelGroupEntry = new SearchTreeGroupEntry(new GUIContent(firstLevelLabel), 1); k_Entries.Add(firstLevelGroupEntry); foreach (var secondLevelKvp in topLevelKvp.Value) { var secondLevelLabel = secondLevelKvp.Key; var secondLevelGroupEntry = new SearchTreeGroupEntry(new GUIContent(secondLevelLabel), 2); k_Entries.Add(secondLevelGroupEntry); foreach (var thirdLevelKvp in secondLevelKvp.Value) { var thirdLevelLabel = thirdLevelKvp.Key; var thirdLevelGroupEntry = new SearchTreeGroupEntry(new GUIContent(thirdLevelLabel), 3); k_Entries.Add(thirdLevelGroupEntry); foreach (var label in thirdLevelKvp.Value) { var entry = new SearchTreeEntry(new GUIContent(label)) { level = 4 }; k_Entries.Add(entry); } } } } }
public List <SearchTreeEntry> CreateSearchTree(SearchWindowContext context) { var tree = new List <SearchTreeEntry> { new SearchTreeGroupEntry(new GUIContent("Create Node")) }; Type[] behaviorTypes = SerializedBehaviorsCollection.GetBehaviorTypes(); Array.Sort(behaviorTypes, s_behaviorTypeComparer); var compositeTypes = new List <Type>(); var decoratorTypes = new List <Type>(); var leafTypes = new List <Type>(); var actionTypes = new List <Type>(); var conditionTypes = new List <Type>(); var statusBehaviorTypes = new List <Type>(); for (int i = 0, count = behaviorTypes.Length; i < count; ++i) { Type behaviorType = behaviorTypes[i]; if (behaviorType.IsSubclassOf(typeof(Composite))) { compositeTypes.Add(behaviorType); } else if (behaviorType.IsSubclassOf(typeof(Decorator))) { decoratorTypes.Add(behaviorType); } else if (behaviorType.IsSubclassOf(typeof(Leaf))) { if (behaviorType.IsSubclassOf(typeof(Action))) { actionTypes.Add(behaviorType); } else if (behaviorType.IsSubclassOf(typeof(Condition))) { conditionTypes.Add(behaviorType); } else if (behaviorType.IsSubclassOf(typeof(StatusBehavior))) { statusBehaviorTypes.Add(behaviorType); } else { leafTypes.Add(behaviorType); } } } var compositesGroup = new SearchTreeGroupEntry(new GUIContent("Composites"), 1); tree.Add(compositesGroup); AddEntries(tree, compositeTypes, compositesGroup); var decoratorsGroup = new SearchTreeGroupEntry(new GUIContent("Decorators"), 1); tree.Add(decoratorsGroup); AddEntries(tree, decoratorTypes, decoratorsGroup); var leavesGroup = new SearchTreeGroupEntry(new GUIContent("Leaves"), 1); tree.Add(leavesGroup); var actionsGroup = new SearchTreeGroupEntry(new GUIContent("Actions"), 2); tree.Add(actionsGroup); AddEntries(tree, actionTypes, actionsGroup); var conditionsGroup = new SearchTreeGroupEntry(new GUIContent("Conditions"), 2); tree.Add(conditionsGroup); AddEntries(tree, conditionTypes, conditionsGroup); var statusBehaviorsGroup = new SearchTreeGroupEntry(new GUIContent("Status Behaviors"), 2); tree.Add(statusBehaviorsGroup); AddEntries(tree, statusBehaviorTypes, statusBehaviorsGroup); AddEntries(tree, leafTypes, leavesGroup); return(tree); }
public SearchGroup(string name, int depth) { Section = new SearchTreeGroupEntry(new GUIContent(name), depth); Entries = new List <SearchTreeEntry>(); }
private List <SearchTreeEntry> CreateSearchTree() { List <SearchTreeEntry> tempTree = new List <SearchTreeEntry>() { new SearchTreeGroupEntry(new GUIContent("Create Elements")) }; foreach (Type type in nodeTypes) { if (AttributeCache.TryGetTypeAttribute(type, out TitleAttribute attribute)) { if (attribute.ShowInList) { GUIContent content = new GUIContent(attribute.Title.Last()); //if (AttributeCache.TryGetTypeAttribute(type, out NodeTooltipAttribute tooltipAttribute)) // content.tooltip = tooltipAttribute.Tooltip; if (attribute.Title.Length > 1) { SearchTreeGroupEntry groupTemp = null; for (int i = 1; i < attribute.Title.Length; i++) { SearchTreeGroupEntry group = tempTree.Find(item => (item.content.text == attribute.Title[i - 1] && item.level == i)) as SearchTreeGroupEntry; if (group == null) { group = new SearchTreeGroupEntry(new GUIContent(attribute.Title[i - 1]), i); int index = groupTemp == null ? 0 : tempTree.IndexOf(groupTemp); tempTree.Insert(index + 1, group); } groupTemp = group; } tempTree.Insert(tempTree.IndexOf(groupTemp) + 1, new SearchTreeEntry(content) { userData = type, level = attribute.Title.Length }); } else { tempTree.Add(new SearchTreeEntry(content) { userData = type, level = 1 }); } } } else { GUIContent content = new GUIContent(ObjectNames.NicifyVariableName(type.Name)); //if (AttributeCache.TryGetTypeAttribute(type, out NodeTooltipAttribute tooltipAttribute)) // content.tooltip = tooltipAttribute.Tooltip; tempTree.Add(new SearchTreeEntry(content) { userData = type, level = 1 }); } } return(tempTree); }