Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for UI Toolkit Elements in PropertyDrawers #177

Open
VikingPingvin opened this issue Nov 4, 2024 · 0 comments
Open

Support for UI Toolkit Elements in PropertyDrawers #177

VikingPingvin opened this issue Nov 4, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@VikingPingvin
Copy link

Describe the bug
When TriInspector is added to the Unity project, CustomPropertyDrawers won't work with UI Toolkit elements, but the UGUI system.
I suspect the behavior is similar to what is explained in this thread: https://discussions.unity.com/t/property-drawers/724398/95

Expected behavior
I'd like to be able to use public override VisualElement CreatePropertyGUI(SerializedProperty property) in my custom propertyDrawers that are not using any TriInspector functionality.

Code Sample

[CustomPropertyDrawer(typeof(WhateverPropertyAttribute))]
public class WhateverPropertyDrawer : PropertyDrawer {
    public override VisualElement CreatePropertyGUI(SerializedProperty property) {
        var container = new VisualElement();
        container.style.flexDirection = FlexDirection.Row;

        var propertyField = new PropertyField(property);
        propertyField.Bind(property.serializedObject);
        propertyField.style.flexGrow = 1; 
        container.Add(propertyField);

        // Create buttons and add them to the container
        Button button1 = new Button(() => Debug.Log("Button 1 pressed")) { text = "B1" };
        Button button2 = new Button(() => Debug.Log("Button 2 pressed")) { text = "B2" };
        Button button3 = new Button(() => Debug.Log("Button 3 pressed")) { text = "B3" };

        container.Add(button1);
        container.Add(button2);
        container.Add(button3);

        return container;
    }

    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
        EditorGUI.PropertyField(position, property, label);
        Debug.LogWarning("UI Toolkit not supported, falling back to IMGUI.");

    }
}

Screenshots

Desktop: Win 11
Unity version: Unity 6 LTS
Tri Inspector version: v1.14.1

@VikingPingvin VikingPingvin added the bug Something isn't working label Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant