Giter Site home page Giter Site logo

Comments (4)

XScorpion2 avatar XScorpion2 commented on September 9, 2024

Actually, I stand corrected, Full Inspector does not recognize a custom editor for a specific enum type.

Code Example:

[System.Flags]
public enum Direction
{
    UP = 1,
    DOWN = 2,
    LEFT = 4,
    RIGHT = 8,
}

using UnityEngine;
using UnityEditor;
using FullInspector;

[CustomPropertyEditor(typeof(Direction))]
public class DirectionEditor : PropertyEditor<Direction>
{
    public override Direction Edit(Rect region, GUIContent label, Direction element)
    {
        return (Direction)EditorGUI.EnumMaskField(region, label, element);
    }

    public override float GetElementHeight(GUIContent label, Direction element)
    {
        return EditorStyles.numberField.CalcHeight(label, 1000);
    }
}

from fullinspector.

jacobdufault avatar jacobdufault commented on September 9, 2024

I'll update the default enum property editor to correctly handle [Flags].

I've additionally adjusted the property editor resolution order to allow for enums to be overriden.

If you want this fix now, then please update PropertyEditor.GetCachedEditors to

private static List<IPropertyEditor> GetCachedEditors(Type propertyType) {
    List<IPropertyEditor> editors;

    if (_cachedPropertyEditors.TryGetValue(propertyType, out editors) == false) {
        editors = new List<IPropertyEditor>();
        _cachedPropertyEditors[propertyType] = editors;

        IPropertyEditor editor;

        // arrays always need special handling; we don't support overriding them
        if ((editor = ArrayPropertyEditor.TryCreate(propertyType)) != null) editors.Add(editor);

        // try to add a user-defined editor
        if (UserDefinedNonGenericPropertyEditors.Value.ContainsKey(propertyType)) {
            editors.Add(UserDefinedNonGenericPropertyEditors.Value[propertyType].Value);
        }

        // try and create an editor from one of the user-defined generic property editors
        if ((editor = TryCreateFromGenericPropertyEditor(propertyType)) != null) editors.Add(editor);

        // try to create an inherited property editor
        if ((editor = TryCreateInheritedPropertyEditor(propertyType)) != null) editors.Add(editor);

        // enums come after generic & inherited to allow them to be overridden
        if ((editor = EnumPropertyEditor.TryCreate(propertyType)) != null) editors.Add(editor);

        // try and create an editor for abstract/interface type
        if ((editor = AbstractTypePropertyEditor.TryCreate(propertyType)) != null) editors.Add(editor);

        // try and create a reflected editor; will only fail for arrays or collections,
        // which should be covered by the array editor
        if ((editor = ReflectedPropertyEditor.TryCreate(propertyType)) != null) editors.Add(editor);
    }

    return editors;
}

Thanks.

from fullinspector.

XScorpion2 avatar XScorpion2 commented on September 9, 2024

I love you sir!

from fullinspector.

jacobdufault avatar jacobdufault commented on September 9, 2024

Additionally, EnumPropertyEditor will be changed to this in 1.2:

/// <summary>
/// Provides a property editor for enums.
/// </summary>
internal class EnumPropertyEditor : IPropertyEditor {
    public object Edit(Rect region, GUIContent label, object element) {
        Enum selected = (Enum)element;

        if (Attribute.IsDefined(selected.GetType(), typeof(FlagsAttribute))) {
            return EditorGUI.EnumMaskField(region, label, selected);
        }

        return EditorGUI.EnumPopup(region, label, selected);
    }

    public float GetElementHeight(GUIContent label, object element) {
        return EditorStyles.popup.CalcHeight(label, 100);
    }

    public static IPropertyEditor TryCreate(Type dataType) {
        if (dataType.IsEnum == false) {
            return null;
        }

        return new EnumPropertyEditor();
    }
}

from fullinspector.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.