Custom VisualTreeAsset inspector fields

Hello everyone,

I am trying to extend the VisualTreeAsset inspector window to add some extra properties to a UXML file within the Unity Editor.
So far, I managed to add some labels and fields, but I noticed that the inputs are disabled (readonly).



I tried to call “EditorGUI.BeginDisabledGroup(false);” at the begining of the “OnInspectorGUI()” method, but that doesn’t help.

There’s my code to achieve this:

[CustomEditor(typeof(VisualTreeAsset))]
[CanEditMultipleObjects]
public class RosalinaUxmlDocumentInspector : Editor
{
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        VisualTreeAsset visualTreeAsset = (VisualTreeAsset)target;

        string assetPath = AssetDatabase.GetAssetPath(visualTreeAsset.GetInstanceID());
        var file = RosalinaSettings.instance.GetFileSetting(assetPath);

        EditorGUI.BeginDisabledGroup(false);
        EditorGUILayout.BeginVertical();
        EditorGUI.BeginChangeCheck();

        GUILayout.Space(20);
        EditorGUILayout.LabelField("Rosalina", EditorStyles.boldLabel);

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.PrefixLabel("Enable");
        bool test = EditorGUILayout.Toggle(file != null);
        EditorGUILayout.EndHorizontal();

        if (file != null)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Code generation type");
            file.Type = (RosalinaGenerationType)EditorGUILayout.EnumPopup(file.Type);
            EditorGUILayout.EndHorizontal();
        }

        if (EditorGUI.EndChangeCheck())
        {

        }
        EditorGUILayout.EndVertical();
        EditorGUI.EndDisabledGroup();
    }
}

How can I enable these fields and that extension work with my settings system? Any ideas ?

Thanks,

Eastrall

I have been doing some reseaches about why my fields are in readonly mode, and from what I saw in Unity’s source code on Github and some answers across the Internet, I am using a “CustomEditor” attribute for the “VisualTreeAsset” type.

On the Unity Answers website, I saw that I should use the importer type instead of the “VisualTreeAsset”. Then I found that Unity was using the UIElementsViewImporter which is internal to the Unity Editor, so I can’t extend it.

Is there any other option to add a custom editor/inspector extension to the UXML files ?

Hello! Since UIElementsViewImporter is internal, you can’t really extend the inspector. We are aware that there is a lot of internal functionality around uxml files and uss files that can be exposed to users. In fact, we have task in our roadmap to work on an API to modify uxml and uss files. Being able to extend the inspector could be part of this effort as well. Sadly, I don’t have an ETA for this but we should start working on it soon.

In the meantime, I think the best you can do is to create a custom window instead of a custom inspector for your added functionality.

Thanks for the reply!
The custom window was my fallback option in case it wasn’t possible to extend the inspector.

I’ll create a custom window in that case!

Thank you.