GUIContent GetTypeName(SerializedProperty property) { // Cache this string. string managedReferenceFullTypename = property.managedReferenceFullTypename; if (string.IsNullOrEmpty(managedReferenceFullTypename)) { return(k_NullDisplayName); } if (m_TypeNameCaches.TryGetValue(managedReferenceFullTypename, out GUIContent cachedTypeName)) { return(cachedTypeName); } Type type = ManagedReferenceUtility.GetType(managedReferenceFullTypename); string typeName = null; AddTypeMenuAttribute typeMenu = TypeMenuUtility.GetAttribute(type); if (typeMenu != null) { typeName = typeMenu.GetTypeNameWithoutPath(); if (!string.IsNullOrWhiteSpace(typeName)) { typeName = ObjectNames.NicifyVariableName(typeName); } } if (string.IsNullOrWhiteSpace(typeName)) { typeName = ObjectNames.NicifyVariableName(type.Name); } GUIContent result = new GUIContent(typeName); m_TypeNameCaches.Add(managedReferenceFullTypename, result); return(result); }
public static void AddTo(AdvancedDropdownItem root, IEnumerable <Type> types) { int itemCount = 0; // Add null item. var nullItem = new AdvancedTypePopupItem(null, TypeMenuUtility.k_NullDisplayName) { id = itemCount++ }; root.AddChild(nullItem); Type[] typeArray = types.OrderByType().ToArray(); // Single namespace if the root has one namespace and the nest is unbranched. bool isSingleNamespace = true; string[] namespaces = new string[kMaxNamespaceNestCount]; foreach (Type type in typeArray) { string[] splittedTypePath = TypeMenuUtility.GetSplittedTypePath(type); if (splittedTypePath.Length <= 1) { continue; } for (int k = 0; (splittedTypePath.Length - 1) > k; k++) { string ns = namespaces[k]; if (ns == null) { namespaces[k] = splittedTypePath[k]; } else if (ns != splittedTypePath[k]) { isSingleNamespace = false; break; } } } // Add type items. foreach (Type type in typeArray) { string[] splittedTypePath = TypeMenuUtility.GetSplittedTypePath(type); if (splittedTypePath.Length == 0) { continue; } AdvancedDropdownItem parent = root; // Add namespace items. if (!isSingleNamespace) { for (int k = 0; (splittedTypePath.Length - 1) > k; k++) { AdvancedDropdownItem foundItem = GetItem(parent, splittedTypePath[k]); if (foundItem != null) { parent = foundItem; } else { var newItem = new AdvancedDropdownItem(splittedTypePath[k]) { id = itemCount++, }; parent.AddChild(newItem); parent = newItem; } } } // Add type item. var item = new AdvancedTypePopupItem(type, ObjectNames.NicifyVariableName(splittedTypePath[splittedTypePath.Length - 1])) { id = itemCount++ }; parent.AddChild(item); } }