public void CreateComponentTree(List <BrowsePopup.Element> tree) { tree.Add(new BrowsePopup.Group(0, "Add New Callable")); HashSet <string> categories = new HashSet <string>(); foreach (var kvp in s_CallableTypes.OrderBy(o => o.Key).OrderBy(o => !o.Key.Contains("/"))) { int i = 0; string cat = string.Join("/", kvp.Key.Split('/').Reverse().Skip(1).Reverse()); string name = kvp.Key.Split('/').Last(); if (!categories.Contains(cat) && cat != "") { string[] split = cat.Split('/'); string current = ""; while (i < split.Length) { current += split[i]; if (!categories.Contains(current)) { tree.Add(new BrowsePopup.Group(i + 1, split[i])); } i++; current += "/"; } categories.Add(cat); } else { i = cat.Split('/').Length; } if (cat != "") { i++; } Texture icon = null; CallableAttribute attr = kvp.Value.GetCustomAttribute <CallableAttribute>(); if (attr != null) { icon = AssetDatabase.LoadAssetAtPath <Texture2D>($"Packages/net.peeweek.gameplay-ingredients/Icons/{attr.iconPath}"); } tree.Add(new CallableElement(i, kvp.Value, icon, () => { addNextComponentInfo.newComponentType = kvp.Value; EditorApplication.delayCall += AddCallable; })); } tree.Add(new CallableElement(1, null, null, () => { addNextComponentInfo.newComponentType = null; EditorApplication.delayCall += AddCallable; })); }
static void BuildMenu() { var types = TypeUtility.GetConcreteTypes <Callable>().OrderBy(o => o.Name); s_CallableTypes = new Dictionary <string, Type>(); foreach (var type in types) { CallableAttribute attr = type.GetCustomAttribute <CallableAttribute>(); string path = string.Empty; if (attr != null) { path += attr.category + "/"; } path += ObjectNames.NicifyVariableName(type.Name); s_CallableTypes[path] = type; } }