static AttributeExampleUtilities() { AttributeRegisterMap = AssemblyUtilities.GetAllAssemblies() .SelectMany(a => a.GetCustomAttributes(typeof(OdinRegisterAttributeAttribute), true)) .Cast <OdinRegisterAttributeAttribute>() .ToDictionary(x => x.AttributeType); AttributeTypes = AttributeRegisterMap.Keys.ToArray(); AttributeIconMap = new Dictionary <Type, Texture>(); }
private TypeTreeNode GetTypeTree(Type type) { TypeTreeNode rootNode; if (typeTrees.TryGetValue(type, out rootNode) == false) { var typeFlag = AssemblyUtilities.GetAssemblyTypeFlag(type.Assembly); var additionalTypes = new List <Type>() { typeof(NullType), type, typeof(string), typeof(List <>).MakeGenericType(type), type.MakeArrayType(), type.MakeArrayType(2), type.MakeArrayType(3) }; var additions = additionalTypes .Select(x => new { type = x, flag = (x == typeof(NullType) || x.IsArray) ? typeFlag : AssemblyUtilities.GetAssemblyTypeFlag(x.Assembly) }) .ToArray(); rootNode = typeTrees[type] = new TypeTreeNode() { ChildNodes = AssemblyUtilities .GetAllAssemblies() .Select(x => new { assembly = x, flag = AssemblyUtilities.GetAssemblyTypeFlag(x) }) .GroupBy(a => a.flag) .Select(a => new TypeTreeNode() { AssemblyTypeFlag = a.Key, IsVisible = (a.Key & AssemblyTypeFlags.UserTypes) != 0, ChildNodes = AssemblyUtilities .GetTypes(a.Key) .Where(x => ((a.Key & AssemblyTypeFlags.UserTypes) != 0 || x.IsPublic) && x != type) // Only include public types or types from User assembly. .Prepend(additions.Where(x => x.flag == a.Key).Select(x => x.type)) .Select(t => CanCreateInstance(type, ref t) ? t : null) .Where(t => t != null) .Distinct() .GroupBy(t => ((t == typeof(NullType) || t.IsArray) ? type : t).Namespace ?? "ALSO!GROUP!ME") .Select(g => new TypeTreeNode() { Namespace = (g.Key == "ALSO!GROUP!ME") ? null : g.Key, ChildNodes = g .Select(t => new TypeTreeNode() { Type = t }) .Where(x => x.Type == null || x.Type.GetNiceName().Contains('$') == false) .OrderBy(t => t.Type == typeof(NullType)) .ThenBy(t => t.Type == null ? "" : t.Type.Name) .ToList() }) .Where(x => x.Type == null || x.Type.GetNiceName().Contains('$') == false) .OrderBy(x => x.Namespace) .ThenBy(x => x.Type) .ToList() }) .OrderBy(x => x.AssemblyTypeFlag) .ToList() }; rootNode.IsVisible = true; rootNode.Initialize(this, null); } else { rootNode.Initialize(this, null); } this.hideFoldoutLabels = rootNode.EnumerateTree().Count(x => x.Type != null) < 20; if (this.hideFoldoutLabels) { foreach (var item in rootNode.EnumerateTree()) { item.IsVisible = true; } } else { var firstCollection = rootNode.EnumerateTree().FirstOrDefault(x => x.ChildNodes != null && x.ChildNodes.Count > 0); if (firstCollection != null) { firstCollection.IsVisible = true; } } var firstTypeNode = rootNode.EnumerateTree().FirstOrDefault(x => x.Type != null); if (firstTypeNode != null) { firstTypeNode.ForceSetSelected = true; } if (this.autoSelectFirst && firstTypeNode != null) { this.chosenType = firstTypeNode.Type; } return(rootNode); }