Example #1
0
        public static void ShowAndCallbackOnSelect(Rect positionUnder, System.Type baseType,
                                                   System.Action <System.Type> callback,
                                                   bool allowAbstractTypes           = false, bool allowInterfaces       = false,
                                                   System.Type defaultType           = null, System.Type[] excludedTypes = null,
                                                   TypeDropDownListingStyle listType = TypeDropDownListingStyle.Namespace)
        {
            int controlID = GUIUtility.GetControlID(TypeSelectionDropDownWindow.s_TypeCustomHash, EditorGUIUtility.native, positionUnder);

            CallbackInfo.instance = new CallbackInfo(controlID, null, callback);
            TypeSelectionDropDownWindow.DisplayCustomMenu(positionUnder, GUIContent.none, baseType, null, allowAbstractTypes, allowInterfaces, defaultType, excludedTypes, listType);
        }
        public static System.Type Popup(Rect position, GUIContent label,
                                        System.Type baseType, System.Type selectedType,
                                        bool allowAbstractTypes           = false, bool allowInterfaces       = false,
                                        System.Type defaultType           = null, System.Type[] excludedTypes = null,
                                        TypeDropDownListingStyle listType = TypeDropDownListingStyle.Namespace,
                                        System.Predicate <System.Type> searchPredicate = null)
        {
            int controlID = GUIUtility.GetControlID(TypeSelectionDropDownWindow.s_TypePopupHash, EditorGUIUtility.native, position);

            position = EditorGUI.PrefixLabel(position, controlID, label);

            selectedType = CallbackInfo.GetSelectedValueForControl(controlID, selectedType);

            var content = GetTypeLabel(selectedType);
            var current = Event.current;
            var type    = current.type;

            switch (type)
            {
            case EventType.KeyDown:
            {
                //TODO?
                //EditorStyles.popup.Draw(position, content, controlID);
            }
            break;

            case EventType.Repaint:
            {
                EditorStyles.popup.Draw(position, content, controlID);
            }
            break;

            case EventType.MouseDown:
            {
                if (current.button == 0 && position.Contains(current.mousePosition))
                {
                    CallbackInfo.instance = new CallbackInfo(controlID, selectedType);
                    TypeSelectionDropDownWindow.DisplayCustomMenu(position, label, baseType, selectedType, allowAbstractTypes, allowInterfaces, defaultType, excludedTypes, listType, searchPredicate);
                    GUIUtility.keyboardControl = controlID;
                    current.Use();
                }
            }
            break;
            }

            return(selectedType);
        }