- Home /
Multiple MENUITEMs Multiple Editor windows
I'm trying to set up multiple menuitems and multiple editor windows. I've been able to display one window, but when I add any more it spits out an error.
public class ToolMenu : EditorWindow
{
[MenuItem("Cool Tools/Item Database")]
static void ItemEditor()
{
EditorWindow.GetWindow(false, "ItemEditor");
}
[MenuItem("Cool Tools/MOBDatabase")] //This was the old way..
static void MOBEditor ()
{
MOBEditor mobwindow = (MOBEditor) EditorWindow.CreateInstance(typeof(MOBEditor));
mobwindow.Show();
}
}
Answer by Bunny83 · Jun 04, 2015 at 11:58 PM
In general avoid using methods that take class names as strings.
The GetWindow method can only open one instance of a Window as it will open and return the existing instance it there is one.
So for EditorWindows where you only want / need one instance you should use GetWindow:
[MenuItem("Cool Tools/Item Database")]
static void OpenItemEditor()
{
GetWindow<ItemEditor>();
}
For windows where you want to be able to open multiple instances you should use CreateInstance:
[MenuItem("Cool Tools/MOBDatabase")]
static void OpenMOBEditor ()
{
MOBEditor mobwindow = CreateInstance<MOBEditor>();
mobwindow.Show();
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Repaint EditorSettings inspector from custom menu item 1 Answer
IN-GAME Menu Items 0 Answers
Is MenuItem supported anymore? 2 Answers