Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
        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));
        }