Example #1
0
        void ShowAddMenu(Rect rect, ReorderableList lst)
        {
            var menu = new GenericMenu();

            TypeUtility.PopulateMenuWithCreateItems(menu, m_AddType, type =>
            {
                var element = serializedProperty.AddArrayElement();
                element.managedReferenceValue = CreateNewInstance(type);
                serializedProperty.serializedObject.ApplyModifiedProperties();
            }, RequiredAttribute);

            AddMenuItems?.Invoke(menu);

            if (menu.GetItemCount() == 0 && NoItemMenuItem != null)
            {
                menu.AddDisabledItem(NoItemMenuItem);
            }

            menu.ShowAsContext();
        }
Example #2
0
        void ShowAddMenu(Rect rect, ReorderableList lst)
        {
            var menu = new GenericMenu();

            var foundTypes = TypeCache.GetTypesDerivedFrom(m_AddType);

            for (int i = 0; i < foundTypes.Count; ++i)
            {
                var type = foundTypes[i];

                if (type.IsAbstract)
                {
                    continue;
                }

                if (RequiredAttribute != null && !Attribute.IsDefined(type, RequiredAttribute))
                {
                    continue;
                }

                menu.AddItem(new GUIContent(ObjectNames.NicifyVariableName(type.Name)), false, () =>
                {
                    var element = serializedProperty.AddArrayElement();
                    element.managedReferenceValue = CreateNewInstance(type);
                    serializedProperty.serializedObject.ApplyModifiedProperties();
                });
            }

            AddMenuItems?.Invoke(menu);

            if (menu.GetItemCount() == 0 && NoItemMenuItem != null)
            {
                menu.AddDisabledItem(NoItemMenuItem);
            }

            menu.ShowAsContext();
        }