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); } }
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); }