Esempio n. 1
0
        //------------------------------------------------------------------------/
        // Methods
        //------------------------------------------------------------------------/
        /// <summary>
        /// Displays an searchable enum popup
        /// </summary>
        /// <param name="position"></param>
        /// <param name="label"></param>
        /// <param name="selected"></param>
        /// <returns></returns>
        public static void EnumPopup(Rect position, string label, Enum selected, System.Action <Enum> onSelected)
        {
            int id = GUIUtility.GetControlID(hash, FocusType.Keyboard, position);

            // Prefix
            GUIContent labelContent = new GUIContent(label);

            position = EditorGUI.PrefixLabel(position, id, labelContent);

            int index = 0;

            // Enum Drawer
            Type enumType = selected.GetType();

            string[]   displayedOptions = GetEnumDisplayNames(enumType);
            GUIContent enumValueContent = new GUIContent(selected.ToString());

            if (StratusSearchablePopup.DropdownButton(id, position, enumValueContent))
            {
                System.Action <int> onSelectIndex = i =>
                {
                    Enum value = GetEnumValue(enumType, i);
                    StratusDebug.Log($"Selected {value}");
                    onSelected(value);
                };
                StratusSearchablePopup.EditorGUI(position, index, displayedOptions, onSelectIndex);
            }
        }
        /// <summary>
        /// Displays an searchable popup for a list of strings
        /// </summary>
        /// <param name="position"></param>
        /// <param name="label"></param>
        /// <param name="selected"></param>
        /// <returns></returns>
        public static void Popup(Rect position, int selectedIndex, string[] displayedOptions, System.Action <int> onSelected)
        {
            int id = GUIUtility.GetControlID(hash, FocusType.Keyboard, position);

            position.height = height;
            //position.width *= 0.5f;
            // Enum Drawer
            GUIContent enumValueContent = new GUIContent(displayedOptions[selectedIndex]);

            if (DropdownButton(id, position, enumValueContent))
            {
                System.Action <int> onSelect = i =>
                {
                    onSelected(i);
                    //string value = displayedOptions[i];
                };
                StratusSearchablePopup.EditorGUI(position, selectedIndex, displayedOptions, onSelect);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Displays an searchable enum popup
        /// </summary>
        /// <param name="position"></param>
        /// <param name="label"></param>
        /// <param name="selected"></param>
        /// <returns></returns>
        public static void EnumPopup(Rect position, GUIContent label, SerializedProperty property)
        {
            int id = GUIUtility.GetControlID(hash, FocusType.Keyboard, position);

            // Prefix
            position = EditorGUI.PrefixLabel(position, id, label);
            // Enum Drawer
            string[]   displayedOptions = property.enumDisplayNames;
            GUIContent enumValueContent = new GUIContent(displayedOptions[property.enumValueIndex]);

            if (StratusSearchablePopup.DropdownButton(id, position, enumValueContent))
            {
                System.Action <int> onSelect = i =>
                {
                    property.enumValueIndex = i;
                    property.serializedObject.ApplyModifiedProperties();
                };
                StratusSearchablePopup.EditorGUI(position, property.enumValueIndex, displayedOptions, onSelect);
            }
        }