Пример #1
0
        /// <summary>
        /// Draws an enum selector field using the enum selector.
        /// </summary>
        public static T DrawEnumField(Rect rect, GUIContent label, GUIContent contentLabel, T value, GUIStyle style = null)
        {
            int  id;
            bool hasFocus;
            Action <EnumSelector <T> > bindSelector;
            Func <IEnumerable <T> >    getResult;

            SirenixEditorGUI.GetFeatureRichControl(rect, out id, out hasFocus);

            if (DrawSelectorButton(rect, contentLabel, style ?? EditorStyles.popup, id, out bindSelector, out getResult))
            {
                var selector = new EnumSelector <T>();

                if (!EditorGUI.showMixedValue)
                {
                    selector.SetSelection(value);
                }

                var window = selector.ShowInPopup(new Vector2(rect.xMin, rect.yMax));

                if (isFlagEnum)
                {
                    window.OnClose += selector.SelectionTree.Selection.ConfirmSelection;
                }

                bindSelector(selector);
            }

            if (getResult != null)
            {
                value = getResult().FirstOrDefault();
            }

            return(value);
        }
Пример #2
0
        private void DrawFirstToolbar()
        {
            GUILayout.Space(1);

            var typeName = "       " + (this.targetType == null ? "Select Type" : this.targetType.GetNiceFullName()) + "   ";
            var rect     = GUILayoutUtility.GetRect(0, 21, SirenixGUIStyles.ToolbarBackground);
            var rect2    = rect.AlignRight(80);
            var rect1    = rect.SetXMax(rect2.xMin);

            TypeSelector.DrawSelectorDropdown(rect1, new GUIContent(typeName), SelectType, btnStyle);

            EditorGUI.BeginChangeCheck();
            this.targetTypeFlags = EnumSelector <AssemblyTypeFlags> .DrawEnumField(rect2, null, new GUIContent("Type Filter"), this.targetTypeFlags, btnStyle);

            if (EditorGUI.EndChangeCheck())
            {
                EditorPrefs.SetInt(TargetTypeFlagsPrefKey, (int)this.targetTypeFlags);
            }

            if (Event.current.type == EventType.Repaint)
            {
                var icon = GUIHelper.GetAssetThumbnail(null, this.targetType ?? typeof(int), false);
                if (icon != null)
                {
                    rect1.x += 8;
                    GUI.DrawTexture(rect1.AlignLeft(16).AlignMiddle(16), icon, ScaleMode.ScaleToFit);
                }
            }
        }
Пример #3
0
        private void DrawSecondToolbar()
        {
            var rect = GUILayoutUtility.GetRect(0, 21);

            if (Event.current.type == EventType.Repaint)
            {
                SirenixGUIStyles.ToolbarBackground.Draw(rect, GUIContent.none, 0);
                SirenixEditorGUI.DrawBorders(rect, 0, 0, 0, 1);
            }

            var rect3 = rect.AlignRight(80);
            var rect2 = rect3.SubX(100).SetWidth(100);
            var rect1 = rect.SetXMax(rect2.xMin);

            EditorGUI.BeginChangeCheck();

            this.memberTypes = EnumSelector <MemberTypeFlags> .DrawEnumField(rect2, null, this.memberTypes, btnStyle);

            this.accessModifiers = EnumSelector <AccessModifierFlags> .DrawEnumField(rect3, null, this.accessModifiers, btnStyle);

            if (EditorGUI.EndChangeCheck())
            {
                EditorPrefs.SetInt(AccessModifierFlagsPrefKey, (int)this.accessModifiers);
                EditorPrefs.SetInt(MemberTypeFlagsPrefKey, (int)this.memberTypes);
            }


            this.DrawSearchField(rect1);
        }
Пример #4
0
        /// <summary>
        /// Draws an enum selector field using the enum selector.
        /// </summary>
        public static T DrawEnumField(GUIContent label, T value)
        {
            int  id;
            bool hasFocus;
            Rect rect;
            Action <EnumSelector <T> > bindSelector;
            Func <IEnumerable <T> >    getResult;

            var display = (isFlagEnum && Convert.ToInt64(value) == 0) ? "None" : (EditorGUI.showMixedValue ? "—" : value.ToString());

            TempFeatureRichControlRect(label, out id, out hasFocus, out rect);

            if (DrawSelectorButton(rect, display, EditorStyles.popup, id, out bindSelector, out getResult))
            {
                var selector = new EnumSelector <T>();

                if (!EditorGUI.showMixedValue)
                {
                    selector.SetSelection(value);
                }

                var window = selector.ShowInPopup(new Vector2(rect.xMin, rect.yMax));

                if (isFlagEnum)
                {
                    window.OnClose += selector.SelectionTree.Selection.ConfirmSelection;
                }

                bindSelector(selector);
            }

            if (getResult != null)
            {
                value       = getResult().FirstOrDefault();
                GUI.changed = true;
            }

            return(value);
        }