예제 #1
0
        public void OnGui(Rect position, bool addSearchField, Action <Type> onSelect, Type activeType)
        {
            var collection = TypeUtilities.GetCollection(AppearanceContext);
            var values     = collection.Values;
            var labels     = collection.Labels;
            var index      = collection.IndexOf(activeType);

            var addEmptyValue = AppearanceContext.AddEmptyValue;

            if (addSearchField)
            {
                var buttonLabel = new GUIContent(labels[index]);
                ToolboxEditorGui.DrawSearchablePopup(position, buttonLabel, index, labels, (i) =>
                {
                    var type = RetriveSelectedType(values, i, addEmptyValue);
                    onSelect?.Invoke(type);
                });
            }
            else
            {
                using (new ZeroIndentScope())
                {
                    EditorGUI.BeginChangeCheck();
                    index = EditorGUI.Popup(position, index, labels);
                    if (EditorGUI.EndChangeCheck())
                    {
                        var type = RetriveSelectedType(values, index, addEmptyValue);
                        onSelect?.Invoke(type);
                    }
                }
            }
        }
        protected override void OnGUISafe(Rect position, SerializedProperty property, GUIContent label)
        {
            //prepare pick button label
            var buttonLabel = property.enumValueIndex >= 0 &&
                              property.enumValueIndex < property.enumDisplayNames.Length
                ? new GUIContent(property.enumDisplayNames[property.enumValueIndex])
                : new GUIContent();
            var id = GUIUtility.GetControlID(FocusType.Keyboard, position);

            //begin the true property
            label = EditorGUI.BeginProperty(position, label, property);
            //draw the prefix label
            position = EditorGUI.PrefixLabel(position, id, label);
            //draw dropdown button, will be used to activate popup
            ToolboxEditorGui.DrawSearchablePopup(position, buttonLabel, property.enumValueIndex, property.enumDisplayNames, (i) =>
            {
                property.serializedObject.Update();
                property.enumValueIndex = i;
                property.serializedObject.ApplyModifiedProperties();
            });
            EditorGUI.EndProperty();
        }