Create EditorWindow from DLL

Hi,

I have an EditorWindow script to download some library scripts into a project.

This project would be compiled when first open it with Unity, but without library scripts, it would produce some errors which blocked my Editor script running. That means no options list in my Unity Menu.

So after finding ways to break this infinite loop, I compiled my EditorWindow script into a dll file. Options appeared in my Unity Menu.

But this window could not be created when clicking this option, dig into the source code I found it was because of ScriptObject.CreateInstance returns a null object due to no file named with this EditorWindow’s class name.

Anybody knows how to resolve it?

Here is code:

[MenuItem("NuGet/Manage NuGet Packages", false, 0)]
        protected static void DisplayNugetWindow()
        {
            Type t = typeof(NugetWindow);
            string title = "";
            bool utility = false;
            bool focus = false;

            UnityEngine.Object[] objectsOfTypeAll = Resources.FindObjectsOfTypeAll(t);
            EditorWindow editorWindow =
                objectsOfTypeAll.Length <= 0 ? (EditorWindow) null : (EditorWindow) objectsOfTypeAll[0];
            if (!(bool) ((UnityEngine.Object) editorWindow))
            {
                editorWindow = ScriptableObject.CreateInstance(t) as NugetWindow;

                if (editorWindow == null)
                {
                    UnityEngine.Debug.LogError("instance could not convert to EditorWindow");
                }

                if (title != null)
                    editorWindow.titleContent = new GUIContent(title);
                if (utility)
                    editorWindow.ShowUtility();
                else
                    editorWindow.Show();
            }
            else if (focus)
            {
                editorWindow.Show();
                editorWindow.Focus();
            }
        }

editorWindow = ScriptableObject.CreateInstance(t) returns null.

Use EditorWindow.GetWindow() instead of ScriptableObject.CreateInstance(t).

Thanks for your reply, but EditorWindow.GetWindow actually invoke ScriptableObject.CreateInstance(t), you could dig into the source code

Fixed by creating a new C# library project and compiling dll.
The project: https://github.com/suntabu/UnityNugetDLL