Beispiel #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);
        }
        /// <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);
        }