Exemple #1
0
        private static void DisplayCustomMenu(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)
        {
            if (_window != null)
            {
                _window.Close();
            }

            var pos = GUIUtility.GUIToScreenPoint(new Vector2(position.x, position.y));

            position.x = pos.x;
            position.y = pos.y;

            _window                    = EditorWindow.CreateInstance <TypeSelectionDropDownWindow>();
            _window.BaseType           = baseType;
            _window.AllowAbstractTypes = allowAbstractTypes;
            _window.AllowInterface     = allowInterfaces;
            _window.DefaultType        = defaultType;
            _window.ExcludedTypes      = excludedTypes;
            _window.ListingStyle       = listType;
            _window.SearchPredicate    = searchPredicate;

            _window.ShowAsDropDown(position, new Vector2(position.width, 320f));
            _window.Focus();
        }
Exemple #2
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,
                                                   System.Predicate <System.Type> searchPredicate = null)
        {
            int controlID = GUIUtility.GetControlID(TypeSelectionDropDownWindow.s_TypePopupHash, FocusType.Passive, positionUnder);

            CallbackInfo.instance = new CallbackInfo(controlID, null, callback);
            TypeSelectionDropDownWindow.DisplayCustomMenu(positionUnder, GUIContent.none, baseType, null, allowAbstractTypes, allowInterfaces, defaultType, excludedTypes, listType, searchPredicate);
        }
Exemple #3
0
        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, FocusType.Passive, 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);
        }