- Home /
Programmatically display Project Wizard
Is there a way to display to project wizard from "Edit/New Project..." or "Edit/Open Project..." programmatically? Making an editor extension to automate some things.
EDIT: I should note that I've looked everywhere I can think of using reflection. Searching for methods and types with the names "Project", "Wizard", "Open" or "New" without success.
Answer by vexe · Jun 14, 2014 at 12:24 AM
This doesn't answer you, but might give you some ideas...
I couldn't find it too. But if you look at its GUI, it looks like a Winform or something which means it's not implemented in Unity's managed dlls. As opposed to the BuildPlayerWindow
which is using Unity's editor API. Analyzing the usage of the show methods in BuildPlayerWindow lead to nowhere (using ILSpy) which probably means it's used from unmanaged land. I looked at BuildPlayerWindow cause I thought if I get close to one of the File/
items I could get close to "New project" - but no... I also managed to find "Save scene" - in EditorApplication.SaveScene
My first reaction when I read your question is to use EditorApplication.ExecuteMenuItem
with "File/New Project" as a parameter. But it didn't work of course cause they're not really menu items...
I then turned to (a hack) sending an Alt+F+N+Enter key combination. Cause, as you might well know, if you press Alt+F you're in the "File" menu, now press N to go "New Project" and Enter/Return to press it. I couldn't do it right though, I first tried getting the current focused window and doing a SendEvent
to it (cause the combo works from any editor window):
var focused = EditorWindow.focusedWindow;
// I tried creating the alt event in many ways, non succeeded:
var alt1 = new Event
{
type = EventType.KeyDown | EventType.KeyUp,
modifiers = EventModifiers.Alt,
alt = true
};
var alt2 = new Event
{
type = EventType.KeyDown,
modifiers = EventModifiers.Alt,
alt = true
};
var alt3 = new Event
{
type = EventType.KeyDown,
modifiers = EventModifiers.Alt,
alt = true
};
var alt4 = new Event
{
type = EventType.KeyDown,
keyCode = KeyCode.LeftAlt
};
focused.SendEvent(any of the previous alts);
I gave up on using SendEvent
, and turned into WinAPI and using my NativeCalls class. I managed to get Alt+F sent, but not N and then Return.
NativeCalls.SendKey(NativeCalls.VirtualKeyCode.ALT);
NativeCalls.SendKey(NativeCalls.VirtualKeyCode.KEY_F);
I linked you the code so maybe you can get it right.