Extend Editor ModelInspector

Hello,

I’m trying to extend the ModelImporter inspector, to put a button on top.
The code below work great for the button, but the standard serialization from UnityEditor is lost.
I try to use C# reflection to recover it but it does not work at the time.

How can I do that ?

namespace EditorTools.UVViewer
{
    using System;
    using System.Reflection;
    using UnityEditor;
    using UnityEngine;

    [CustomEditor(typeof(ModelImporter))]
    public class EditorExtend : Editor
    {
        private void DisplayModelInspectorGUI()
        {
            Type type = Type.GetType("UnityEditor.ModelImporterModelEditor,UnityEditor");

            if(type != null)
            {
                MethodInfo info = type.GetMethod("OnInspectorGUI");

                if(info != null)
                {
                    object classInstance = Activator.CreateInstance(type, null);
                    info.Invoke(classInstance, null);
                }
            }
        }

        public override void OnInspectorGUI()
        {
            if (GUILayout.Button("Open UVViewer"))
            {
                UVViewer window = EditorWindow.GetWindow<UVViewer>();
            }
            EditorGUILayout.Space();

            DisplayModelInspectorGUI();
            //DrawDefaultInspector();
        }
    }
}

Cannot check if for your right now, but drawdefaultinspector() after your button should do the trick?

Floris Weers

The DrawDefaultInspector() came from the inheritance of the Editor class and display the “default” inspector like on the picture attached.
I would like to recover the serialization with the three buttons (Model/Rig/Animations).
But I don’t really know if it is possible.

2323272--156715--Capture.PNG

Hey,

I just did the same thing. You have to use Editor.Create(this.targets, type) instead of Activator.CreateInstance(type) to make it work.

Editor.CreateEditor?

Doesn’t seem to work though.