Custom Inspector Element on Texture Importer?

I'm trying to get a custom editor to show up in the inspector for textures. If I use

@CustomEditor(TextureImporter) 

it overwrites the Texture Importer settings. How would I go about attaching this to the inspector for images?

alt text

ext!


@CustomEditor(TextureImporter) 
class Texture2DEditor extends Editor {

    var drawDefaultInspector : boolean;
    var drawExtendedInspector : boolean;

    function OnInspectorGUI() {
        GUI.enabled = true;

        drawDefaultInspector = GUILayout.Toggle(drawDefaultInspector, "Default Inspector", EditorStyles.toolbarDropDown);
        if (drawDefaultInspector) DrawDefaultInspector(); 
        drawExtendedInspector = GUILayout.Toggle(drawExtendedInspector, "Extended Inspector", EditorStyles.toolbarDropDown);
        if (drawExtendedInspector) DrawExtendedInspector();
    }

    function DrawExtendedInspector() {
        GUILayout.Label("Hello OnInspectorGUI!");
    }       
}


Note that you have to redo the upper portion, I was unable to draw the built in inspector. I also tried Texture2D editors but they didn't work well either (check answer revision history). I checked out the built in texture inspector in UnityEditor.dll, but it uses internal functions that are inaccessible. You might be able to use reflection to invoke them but if I remember correctly, they have application security that deny those operations so you're out of luck if that is the case. Anyhow, it's the best I can give.

I came to the conclusion that you can't easily do this. A much easier approach would be to make another editor window that sits next to your inspector. I know it's not ideal but I think it's the best we can do until Unity Technologies open up more customization options for inspectors. The script is very minimal at its current state but you should be able to extend it to fit your likings.


alt text


class TextureInspector extends EditorWindow {
    var scrollView : Vector2;

    @MenuItem("Window/Texture Inspector")
    static function OpenWindow() {
        var window : TextureInspector = EditorWindow.GetWindow (TextureInspector);
        window.title = "T2D Inspector";
    }

    function OnGUI() {
        var textures = Selection.GetFiltered(Texture2D, SelectionMode.Assets);
        scrollView = GUILayout.BeginScrollView(scrollView);
        GUILayout.Label ("Selected Textures", EditorStyles.boldLabel);
        for (var texture : Texture2D in textures) {
            EditorGUILayout.InspectorTitlebar(true, texture);
            DrawInspector(texture);
        }
        GUILayout.EndScrollView();
        Repaint();
    }

    function DrawInspector(texture : Texture2D) {
        GUILayout.Label("Add your custom inspection here");
    }
}