public void SetTypes(IEnumerable <Type> types) { if (DisplayNullAtFirst) { types = types?.Prepend(null); } m_Types = types?.OrderByType().ToArray(); var builder = new StringBuilder(); m_TypeDisplayNames = m_Types?.Select(type => { if (type == null) { return(NullDisplayLabel); } AddTypeMenuAttribute typeDisplayName = TypeMenuUtility.GetAttribute(type); if (typeDisplayName != null) { return(new GUIContent(ObjectNames.NicifyVariableName(typeDisplayName.MenuName))); } builder.Clear(); string[] names = type.FullName.Split('.'); for (int i = 0; names.Length > i; i++) { // Append type name. bool isLastIndex = (i == (names.Length - 1)); builder.Append(isLastIndex ? ObjectNames.NicifyVariableName(names[i]) : names[i]); if (isLastIndex) { break; } // Append sparator. builder.Append((i == (names.Length - 2)) ? '/' : '.'); } return(new GUIContent(builder.ToString())); }).ToArray(); m_TypeFullNames = m_Types?.Select(type => (type != null) ? $"{type.Assembly.ToString().Split(',')[0]} {type.FullName}" : string.Empty).ToArray(); }
public static string[] GetSplittedTypePath(Type type) { AddTypeMenuAttribute typeMenu = GetAttribute(type); if (typeMenu != null) { return(typeMenu.GetSplittedMenuName()); } else { int splitIndex = type.FullName.LastIndexOf('.'); if (splitIndex >= 0) { return(new string[] { type.FullName.Substring(0, splitIndex), type.FullName.Substring(splitIndex + 1) }); } else { return(new string[] { type.Name }); } } }
static string GetTypeName(SerializedProperty property) { if (string.IsNullOrEmpty(property.managedReferenceFullTypename)) { return(TypeMenuUtility.k_NullDisplayName); } Type type = property.GetManagedReferenceType(); AddTypeMenuAttribute typeMenu = TypeMenuUtility.GetAttribute(type); if (typeMenu != null) { string typeName = typeMenu.GetTypeNameWithoutPath(); if (!string.IsNullOrWhiteSpace(typeName)) { return(ObjectNames.NicifyVariableName(typeName)); } } return(ObjectNames.NicifyVariableName(type.Name)); }
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); }