- Home /
EditorWindow not working when defined in .net/mono Assembly.
Using Visual Studio and Unity 3.0.0f5, I'm trying to define a EditorWindow Class In an external .net assembly.
using System; using UnityEditor; using UnityEngine;
public class MyCustomWindow : EditorWindow { private static MyCustomWindow _windowInstance = null; [MenuItem("Window/Test")] public static void Init() {
MyCustomWindow e = MyCustomWindow.CreateInstance<MyCustomWindow>();
if (_windowInstance != e)
{
e.SomeOperation();
}
_windowInstance = e;
}
public void SomeOperation()
{
Debug.Log("Ran some operation");
}
}
//output error on menu selection //Instance of MyCustomWindow couldn't be created because there is no script with that name. //UnityEngine.ScriptableObject:CreateInstance() //MyCustomWindow:Init()
The menu selection Item appears, but when used it gives the above output. I have an idea that I will have to, if possible, manually register MyCustomWindow to some list of window classes.
Has anyone successfully put an EditorWindow class in a .net assembly dll?
Answer by Alex-Chouls · Oct 21, 2010 at 09:30 PM
I use a small wrapper script that calls the class in the dll.
The wrapper class is a regular script that extends EditorWindow and keeps a reference to the dll class. It then forwards any EditorWindow events you're interested in handling to the class in the dll. Note, the class in the dll does NOT extend EditorWindow, it just implements the functionality (OnGUI etc.)
Typically the wrapper class initializes the dll class with itself, so the dll class can call EditorWindow methods, e.g., Close()...
Tried to copy/paste some code, but the formatting controls in this edit box suck and I ran out of patience!
I also tried the "Adapter" method described in this thread, but could't get it to work with EditorWindow...
If you find a better way to do this, please share!
Thanks for your answer! I'm about at where you are; settled with the wrapper solution
Answer by Mudloop · Mar 24, 2012 at 05:11 PM
I'm not sure if this is new in Unity 3.5, but placing the dll in an Editor folder seems to work for me. So I work with two separate dlls - one for the game classes, and one for the editor classes.
Your answer
Follow this Question
Related Questions
EditorWindow reference to other scripts functions 0 Answers
Weird bug when dragging object onto EditorGUILayout.ObjectField 0 Answers
Creating Editor 2D Animation Preview 2 Answers
mouseposition and clicks in editor sceneview 0 Answers
EditorWindow, Utility Popup, not using custom PropertyDrawers 0 Answers