示例#1
0
        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);

            // Add type items.
            foreach (Type type in types.OrderByType())
            {
                string[] splittedTypePath = TypeMenuUtility.GetSplittedTypePath(type);
                if (splittedTypePath.Length == 0)
                {
                    continue;
                }

                AdvancedDropdownItem parent = root;

                // Add namespace items.
                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);
            }
        }
示例#2
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();
        }
        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));
        }